What is Memory?
Store facts about each user and recall them in later conversations.
Customer-facing agents and personal assistants often serve the same user across many conversations. Memory keeps facts such as preferences, responsibilities, and recurring goals available across those conversations.
Install dependencies and set your key before running the examples:
pip install agno openai sqlalchemy
export OPENAI_API_KEY="your-api-key"from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
agent = Agent(
model=OpenAIResponses(id="gpt-5.4-mini"),
db=SqliteDb(db_file="tmp/memory.db"),
update_memory_on_run=True,
)
agent.print_response(
"I prefer email updates and morning meetings.",
user_id="sarah",
session_id="onboarding",
)
agent.print_response(
"How should you schedule and send my project updates?",
user_id="sarah",
session_id="project-planning",
)The first run stores useful facts for sarah. The second run uses the same user_id, so the agent can recall those facts in a different session.
How Memory Works
user_ididentifies whose memories should be loaded.- The configured database stores each user's memory records.
- Stored memories for that user are added to the model context for later runs.
- The selected memory mode controls when records are created, updated, or deleted.
Use a stable application user ID for every run that should share the same memories.
Choose a Memory Mode
| Mode | Configuration | Use it when |
|---|---|---|
| Automatic | update_memory_on_run=True | Each user input should be processed into memories automatically |
| Agentic | enable_agentic_memory=True | The model should decide when to create or update memories during a run |
Automatic memory applies one consistent extraction step during each run. Agentic memory adds an update_user_memory tool and lets the model choose when to call it. Existing memories are loaded into the model context. Automatic extraction exposes add, update, and delete operations; it does not expose clearing all memories. In agentic mode, the default memory manager permits creating and updating memories. Configure MemoryManager(delete_memories=True, clear_memories=True) to allow agentic deletion and clearing. These manager flags do not restrict the automatic extraction path.
When both settings are enabled, agentic memory takes precedence and the automatic extraction step is skipped. Choose one mode for each agent.
Memory, History, and State
| Feature | Stores | Scope | Use it for |
|---|---|---|---|
| Memory | Extracted facts about a user | user_id across sessions | Preferences, profile details, recurring goals |
| Chat history | Messages and tool calls from previous runs | session_id | Conversational continuity within one thread |
| Session state | Application data managed by code or tools | session_id | Carts, task lists, workflow progress, counters |
These features can work together. A support agent can use memory for the customer's communication preference, history for the current ticket, and state for the ticket status.
Store and Inspect Memories
Memories use the database configured on the agent. The default table or collection name is agno_memories.
| Database backend | Custom-name parameter |
|---|---|
| SQL and other table-backed databases | memory_table |
| MongoDB and Firestore | memory_collection |
memories = agent.get_user_memories(user_id="sarah")
for memory in memories or []:
print(memory.memory_id, memory.memory)Manual retrieval is useful for customer profile screens, debugging, review, and deletion workflows. You can also manage memories in the AgentOS UI.