Custom Memory Manager
This example shows how you can configure the Memory Manager.
We also set custom system prompts for the memory manager. You can either override the entire system prompt or add additional instructions which is added to the end of the system prompt.
Code
1from kern.agent import Agent2from kern.db.postgres import PostgresDb3from kern.memory import MemoryManager4from kern.models.openai import OpenAIResponses5from rich.pretty import pprint67db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"89db = PostgresDb(db_url=db_url)1011# You can also override the entire `system_message` for the memory manager12memory_manager = MemoryManager(13 model=OpenAIResponses(id="gpt-5.2"),14 additional_instructions="""15 IMPORTANT: Don't store any memories about the user's name. Just say "The User" instead of referencing the user's name.16 """,17 db=db,18)1920john_doe_id = "john_doe@example.com"2122agent = Agent(23 model=OpenAIResponses(id="gpt-5.2"),24 db=db,25 memory_manager=memory_manager,26 update_memory_on_run=True,27 user_id=john_doe_id,28)2930agent.print_response(31 "My name is John Doe and I like to swim and play soccer.", stream=True32)3334agent.print_response("I dont like to swim", stream=True)353637memories = agent.get_user_memories(user_id=john_doe_id)3839print("John Doe's memories:")40pprint(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 custom_memory_manager.py