User Memories
Here’s a simple example of using Memory in an Agent.memory_demo.py
Read more about Memory in the Memory Overview page.
Developer Resources
- View the Agent schema
- View Examples
- View Cookbook
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Memory gives an Agent the ability to recall information about the user.
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.db.postgres import PostgresDb
from rich.pretty import pprint
user_id = "ava"
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(
db_url=db_url,
memory_table="user_memories", # Optionally specify a table name for the memories
)
# Initialize Agent
memory_agent = Agent(
model=OpenAIChat(id="gpt-4.1"),
db=db,
# Give the Agent the ability to update memories
enable_agentic_memory=True,
# OR - Run the MemoryManager automatically after each response
enable_user_memories=True,
markdown=True,
)
db.clear_memories()
memory_agent.print_response(
"My name is Ava and I like to ski.",
user_id=user_id,
stream=True,
stream_events=True,
)
print("Memories about Ava:")
pprint(memory_agent.get_user_memories(user_id=user_id))
memory_agent.print_response(
"I live in san francisco, where should i move within a 4 hour drive?",
user_id=user_id,
stream=True,
stream_events=True,
)
print("Memories about Ava:")
pprint(memory_agent.get_user_memories(user_id=user_id))
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
enable_user_memories=True which always runs the MemoryManager after each
user message.