Memory Manager
Use a MemoryManager to give agents persistent memory across sessions.
1"""2Memory Manager3=============================45Use a MemoryManager to give agents persistent memory across sessions.6"""78from kern.agent import Agent9from kern.db.sqlite import SqliteDb10from kern.memory.manager import MemoryManager11from kern.models.openai import OpenAIResponses1213# ---------------------------------------------------------------------------14# Create Agent15# ---------------------------------------------------------------------------16db = SqliteDb(db_file="tmp/memory_demo.db")1718agent = Agent(19 model=OpenAIResponses(id="gpt-5.2"),20 db=db,21 # Enable agentic memory so the agent can store and retrieve memories22 enable_agentic_memory=True,23 # Provide a MemoryManager for structured memory operations24 memory_manager=MemoryManager(25 db=db,26 model=OpenAIResponses(id="gpt-5-mini"),27 ),28 markdown=True,29)3031# ---------------------------------------------------------------------------32# Run Agent33# ---------------------------------------------------------------------------34if __name__ == "__main__":35 # First interaction: tell the agent something to remember36 agent.print_response(37 "My name is Alice and I prefer Python over JavaScript.",38 stream=True,39 )4041 print("\n--- Second interaction ---\n")4243 # Second interaction: the agent should recall the preference44 agent.print_response(45 "What programming language do I prefer?",46 stream=True,47 )Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/06_memory_and_learning45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python memory_manager.py