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"
memory_agent.py
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

  1. user_id identifies whose memories should be loaded.
  2. The configured database stores each user's memory records.
  3. Stored memories for that user are added to the model context for later runs.
  4. 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

ModeConfigurationUse it when
Automaticupdate_memory_on_run=TrueEach user input should be processed into memories automatically
Agenticenable_agentic_memory=TrueThe 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

FeatureStoresScopeUse it for
MemoryExtracted facts about a useruser_id across sessionsPreferences, profile details, recurring goals
Chat historyMessages and tool calls from previous runssession_idConversational continuity within one thread
Session stateApplication data managed by code or toolssession_idCarts, 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 backendCustom-name parameter
SQL and other table-backed databasesmemory_table
MongoDB and Firestorememory_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.

Next Steps