Agent Memory
Memory gives an Agent the ability to recall information about the user.
Memory is a part of the Agent's context that helps it provide the best, most personalized response.
Tip
If the user tells the Agent they like to ski, then future responses can reference this information to provide a more personalized experience.
User Memories
Here's a simple example of using Memory in an Agent.
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses3from kern.db.postgres import PostgresDb4from rich.pretty import pprint56user_id = "ava"78db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"910db = PostgresDb(11 db_url=db_url,12 memory_table="user_memories", # Optionally specify a table name for the memories13)141516# Initialize Agent17memory_agent = Agent(18 model=OpenAIResponses(id="gpt-5.2"),19 db=db,20 # Give the Agent the ability to update memories21 enable_agentic_memory=True,22 # OR - Run the MemoryManager automatically after each response23 update_memory_on_run=True,24 markdown=True,25)2627db.clear_memories()2829memory_agent.print_response(30 "My name is Ava and I like to ski.",31 user_id=user_id,32 stream=True,33)34print("Memories about Ava:")35pprint(memory_agent.get_user_memories(user_id=user_id))3637memory_agent.print_response(38 "I live in san francisco, where should i move within a 4 hour drive?",39 user_id=user_id,40 stream=True,41)42print("Memories about Ava:")43pprint(memory_agent.get_user_memories(user_id=user_id))Tip
enable_agentic_memory=True gives the Agent a tool to manage memories of the
user, this tool passes the task to the MemoryManager class. You may also set
update_memory_on_run=True which always runs the MemoryManager after each
user message.
Note
Read more about Memory in the Memory Overview page.
Developer Resources
- View the Agent schema
- View Memory examples
- View Cookbook