Sessions vs memory
They solve different problems. Use both.Identifiers
Pass both on every run. Threads are scoped by
session_id. Memory is scoped by user_id.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Persistent multi-turn conversations and per-user memory.
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses
db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")
agent = Agent(
model=OpenAIResponses(id="gpt-5.5"),
db=db,
add_history_to_context=True,
num_history_runs=5,
enable_agentic_memory=True,
)
agent.run(
"My name is Sarah and I prefer email over phone.",
user_id="sarah@acme.com",
session_id="thread-42",
)
reply = agent.run(
"What's the best way to reach me?",
user_id="sarah@acme.com",
session_id="thread-42",
).content
# Uses both the thread history and the stored memory about Sarah.
| Session history | Memory | |
|---|---|---|
| Stores | The messages in this conversation thread | Learned facts about the user |
| Scope | One session_id | One user_id, across all their sessions |
| Enable with | add_history_to_context=True | enable_agentic_memory=True or update_memory_on_run=True |
| Answers | ”What did we just discuss?" | "What do I know about this person?” |
| Identifier | Distinguishes | Maps to in your product |
|---|---|---|
user_id | The person | Your auth subject (user ID, email) |
session_id | A conversation thread for that person | A chat tab, a Slack thread, a support case |
session_id. Memory is scoped by user_id.
| Mode | Set | Use when |
|---|---|---|
| Automatic | update_memory_on_run=True | Compute memory after every run. |
| Agentic | enable_agentic_memory=True | The agent decides using tool calls. |
memories = agent.get_user_memories(user_id="sarah@acme.com")
| Technique | Effect |
|---|---|
num_history_runs=N | Only the last N turns flow into context |
Session summaries (enable_session_summaries=True) | Older turns are condensed into a running summary |
| Task | Guide |
|---|---|
| Put this behind an HTTP API | Serve as an API |
| Carry memory across Slack and web | Interfaces |
| Give the agent live data | Connecting your data |