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.
from agno.agent.agent import Agentfrom agno.memory.v2.db.sqlite import SqliteMemoryDbfrom agno.memory.v2.memory import Memoryfrom agno.models.openai import OpenAIChatfrom rich.pretty import pprintmemory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")# No need to set the model, it gets set by the agent to the agent's modelmemory = Memory(db=memory_db)# Reset the memory for this examplememory.clear()john_doe_id = "[email protected]"agent = Agent( model=OpenAIChat(id="gpt-4o-mini"), memory=memory, enable_agentic_memory=True,)agent.print_response( "My name is John Doe and I like to hike in the mountains on weekends.", stream=True, user_id=john_doe_id,)agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)memories = memory.get_user_memories(user_id=john_doe_id)print("Memories about John Doe:")pprint(memories)agent.print_response( "Remove all existing memories of me.", stream=True, user_id=john_doe_id,)memories = memory.get_user_memories(user_id=john_doe_id)print("Memories about John Doe:")pprint(memories)agent.print_response( "My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id)memories = memory.get_user_memories(user_id=john_doe_id)print("Memories about John Doe:")pprint(memories)agent.print_response( "I don't pain anymore, i draw instead.", stream=True, user_id=john_doe_id)memories = memory.get_user_memories(user_id=john_doe_id)print("Memories about John Doe:")pprint(memories)