If the user tells the Agent they like to ski, then future responses can reference this information to provide a more personalized experience.
- Session Storage (chat history and session state): Session storage saves an Agent’s sessions in a database and enables Agents to have multi-turn conversations. Session storage also holds the session state, which is persisted across runs because it is saved to the database after each run. Session storage is a form of short-term memory called “Storage” in Agno.
- User Memories (user preferences): The Agent can store insights and facts about the user that it learns through conversation. This helps the agents personalize its response to the user it is interacting with. Think of this as adding “ChatGPT like memory” to your agent. This is called “Memory” in Agno.
- Session Summaries (chat summary): The Agent can store a condensed representations of the session, useful when chat histories gets too long. This is called “Summary” in Agno.
It is relatively easy to use your own memory implementation using
Agent.context.Show me the code: Memory & Storage in Action
Here’s a simple but complete example of using Memory and Storage in an Agent.memory_demo.py
Notes
enable_agentic_memory=Truegives the Agent a tool to manage memories of the user, this tool passes the task to theMemoryManagerclass. You may also setenable_user_memories=Truewhich always runs theMemoryManagerafter each user message.add_history_to_messages=Trueadds the chat history to the messages sent to the Model, thenum_history_runsdetermines how many runs to add.read_chat_history=Trueadds a tool to the Agent that allows it to read chat history, as it may be larger than what’s included in thenum_history_runs.
Default Memory
Every Agent comes with built-in memory which keeps track of the messages in the session i.e. the chat history. You can access these messages usingagent.get_messages_for_session().
We can give the Agent access to the chat history in the following ways:
- We can set
add_history_to_messages=Trueandnum_history_runs=5to add the messages from the last 5 runs automatically to every message sent to the agent. - We can set
read_chat_history=Trueto provide aget_chat_history()tool to your agent allowing it to read any message in the entire chat history. - We recommend setting all 3:
add_history_to_messages=True,num_history_runs=3andread_chat_history=Truefor the best experience. - We can also set
read_tool_call_history=Trueto provide aget_tool_call_history()tool to your agent allowing it to read tool calls in reverse chronological order.
The default memory is not persisted across execution cycles. So after the script finishes running, or the request is over, the built-in default memory is lost.You can persist this memory in a database by adding a
storage driver to the Agent.1
Built-in memory example
agent_memory.py
2
Run the example
Install librariesExport your keyRun the example
Session Storage
The built-in memory is only available during the current execution cycle. Once the script ends, or the request is over, the built-in memory is lost. Storage help us save Agent sessions and state to a database or file. Adding storage to an Agent is as simple as providing astorage driver and Agno handles the rest. You can use Sqlite, Postgres, Mongo or any other database you want.
Here’s a simple example that demonstrates persistence across execution cycles:
storage.py
User Memories
Along with storing session history and state, Agents can also create user memories based on the conversation history. To enable user memories, give your Agent aMemory object and set enable_agentic_memory=True.
Enabling agentic memory will also add all existing user memories to the agent’s system prompt.
1
User memory example
user_memory.py
2
Run the example
Install librariesExport your keyRun the example
Memory object and persisted in the SqliteMemoryDb to be used across multiple users and multiple sessions.
Session Summaries
To enable session summaries, setenable_session_summaries=True on the Agent.
1
Session summary example
session_summary.py
2
Run the example
Install librariesExport your keyRun the example