Team with Agentic Memory
This example demonstrates how to use agentic memory with a team. Unlike simple memory storage, agentic memory allows the AI to actively create, update, and delete user memories during each run based on the conversation context, providing intelligent memory management.
Code
1"""2This example shows you how to use persistent memory with an Agent.34During each run the Agent can create/update/delete user memories.56To enable this, set `enable_agentic_memory=True` in the Agent config.7"""89from kern.agent import Agent10from kern.db.postgres import PostgresDb11from kern.memory import MemoryManager # noqa: F40112from kern.models.openai import OpenAIResponses13from kern.team import Team1415db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"16db = PostgresDb(db_url=db_url)1718john_doe_id = "john_doe@example.com"1920agent = Agent(21 model=OpenAIResponses(id="gpt-5.2"),22)2324team = Team(25 model=OpenAIResponses(id="gpt-5.2"),26 members=[agent],27 db=db,28 enable_agentic_memory=True,29)3031team.print_response(32 "My name is John Doe and I like to hike in the mountains on weekends.",33 stream=True,34 user_id=john_doe_id,35)3637team.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)3839# More examples:40# agent.print_response(41# "Remove all existing memories of me.",42# stream=True,43# user_id=john_doe_id,44# )4546# agent.print_response(47# "My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id48# )4950# agent.print_response(51# "I don't pain anymore, i draw instead.", stream=True, user_id=john_doe_id52# )Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai openai psycopg sqlalchemySet up PostgreSQL database
Start PostgreSQL with pgvector and update the connection string in the code as needed.
Set environment variables
1export OPENAI_API_KEY=your_openai_api_key_hereRun the example
1python team_with_agentic_memory.py