Agentic Memory
This example shows you how to use persistent memory with an Agent.
During each run the Agent can create/update/delete user memories.
To enable this, set enable_agentic_memory=True in the Agent config.
Code
1from kern.agent import Agent2from kern.db.postgres import PostgresDb3from kern.models.openai import OpenAIResponses4from rich.pretty import pprint56db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"78db = PostgresDb(db_url=db_url)91011john_doe_id = "john_doe@example.com"1213agent = Agent(14 model=OpenAIResponses(id="gpt-5.2"),15 db=db,16 enable_agentic_memory=True,17)1819agent.print_response(20 "My name is John Doe and I like to hike in the mountains on weekends.",21 stream=True,22 user_id=john_doe_id,23)2425agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)2627memories = agent.get_user_memories(user_id=john_doe_id)28print("Memories about John Doe:")29pprint(memories)303132agent.print_response(33 "Remove all existing memories of me.",34 stream=True,35 user_id=john_doe_id,36)3738memories = agent.get_user_memories(user_id=john_doe_id)39print("Memories about John Doe:")40pprint(memories)4142agent.print_response(43 "My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id44)4546memories = agent.get_user_memories(user_id=john_doe_id)47print("Memories about John Doe:")48pprint(memories)495051agent.print_response(52 "I don't paint anymore, i draw instead.", stream=True, user_id=john_doe_id53)5455memories = agent.get_user_memories(user_id=john_doe_id)5657print("Memories about John Doe:")58pprint(memories)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-aiRun Example
1python agentic_memory.py