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 Agent
2from kern.models.openai import OpenAIResponses
3from kern.db.postgres import PostgresDb
4from rich.pretty import pprint
5
6user_id = "ava"
7
8db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
9
10db = PostgresDb(
11 db_url=db_url,
12 memory_table="user_memories", # Optionally specify a table name for the memories
13)
14
15
16# Initialize Agent
17memory_agent = Agent(
18 model=OpenAIResponses(id="gpt-5.2"),
19 db=db,
20 # Give the Agent the ability to update memories
21 enable_agentic_memory=True,
22 # OR - Run the MemoryManager automatically after each response
23 update_memory_on_run=True,
24 markdown=True,
25)
26
27db.clear_memories()
28
29memory_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))
36
37memory_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