If you’re building intelligent agents, you need to give them memory which is the ability to remember, reason and personalize responses to users. Memory comes in 3 shapes:

  1. Chat History: This is the current conversation between users and the agent, stored as sessions in chronological order. This is the most basic form of memory and called “Storage” in Agno.
  2. User Memories: Insights and facts about users extracted from conversations, helping agents personalize their responses to users. Think of this as adding a “ChatGPT like memory” to your agent. This is called “Memory” in Agno.
  3. Session Summaries: Condensed representations of conversations, useful when chat histories grow too long. This is called “Summary” in Agno.

Memory helps Agents:

  • Manage conversation state (chat history)
  • Personalize responses to users (user memories)
  • Maintain long-session context (session summaries)

Memory is critical for personal assistants, it allows Agents to “Remember” and “Personalize” their responses to users.

Built-in Memory

Every Agent comes with built-in memory that can be used to access the historical runs per session.

You can give your agent access to chat history in the following ways:

  • You can set add_history_to_messages=True and num_history_responses=5 to add the previous 5 messages automatically to every message sent to the agent.
  • You can set read_chat_history=True to provide a get_chat_history() tool to your agent allowing it to read any message in the entire chat history.
  • You can set read_tool_call_history=True to provide a get_tool_call_history() tool to your agent allowing it to read tool calls in reverse chronological order.
1

Built-in memory example

agent_memory.py
from agno.agent import Agent
from agno.models.google.gemini import Gemini
from rich.pretty import pprint

agent = Agent(
    model=Gemini(id="gemini-2.0-flash-exp"),
    # Set add_history_to_messages=true to add the previous chat history to the messages sent to the Model.
    add_history_to_messages=True,
    # Number of historical responses to add to the messages.
    num_history_responses=3,
    description="You are a helpful assistant that always responds in a polite, upbeat and positive manner.",
)

# -*- Create a run
agent.print_response("Share a 2 sentence horror story", stream=True)
# -*- Print the messages in the memory
pprint([m.model_dump(include={"role", "content"}) for m in agent.memory.messages])

# -*- Ask a follow up question that continues the conversation
agent.print_response("What was my first message?", stream=True)
# -*- Print the messages in the memory
pprint([m.model_dump(include={"role", "content"}) for m in agent.memory.messages])
2

Run the example

Install libraries

pip install google-genai agno

Export your key

export GOOGLE_API_KEY=xxx

Run the example

python agent_memory.py

Persistent Memory

The built-in memory only lasts while the session is active. To persist chat history across sessions, we can store agent sessions in a database using AgentStorage.

Storage is a necessary component when building user facing AI products as any production application will require users to be able to “continue” their conversation with the Agent.

1

Persistent memory example

Let’s test this out, create a file persistent_memory.py with the following code:

persistent_memory.py
import json

from rich.console import Console
from rich.panel import Panel
from rich.json import JSON

from agno.agent import Agent
from agno.models.google.gemini import Gemini
from agno.storage.sqlite import SqliteStorage

agent = Agent(
    model=Gemini(id="gemini-2.0-flash-exp"),
    # Store agent sessions in a database
    storage=SqliteStorage(table_name="agent_sessions", db_file="tmp/agent_storage.db"),
    # Set add_history_to_messages=true to add the previous chat history to the messages sent to the Model.
    add_history_to_messages=True,
    # Number of historical responses to add to the messages.
    num_history_responses=3,
    # Description creates a system prompt for the agent
    description="You are a helpful assistant that always responds in a polite, upbeat and positive manner.",
)

console = Console()

def print_chat_history(agent):
    # -*- Print history
    console.print(
        Panel(
            JSON(json.dumps([m.model_dump(include={"role", "content"}) for m in agent.memory.messages]), indent=4),
            title=f"Chat History for session_id: {agent.session_id}",
            expand=True,
        )
    )

session_id = "xxxx-xxxx-xxxx-xxxx"

# -*- Create a run
agent.print_response("Share a 2 sentence horror story", stream=True, session_id=session_id)
# -*- Print the chat history
print_chat_history(agent)

# -*- Ask a follow up question that continues the conversation
agent.print_response("What was my first message?", stream=True, session_id=session_id)
# -*- Print the chat history
print_chat_history(agent)
2

Run the example

Install libraries

pip install google-genai agno

Export your key

export GOOGLE_API_KEY=xxx

Run the example

python persistent_memory.py

You can view the agent sessions in the sqlite database and continue any conversation by providing the same session_id.

Read more in the storage section.

Creating User Memories

Along with storing chat history and run messages, Memory can be used by the agent to create user memories based on the conversation history.

To enable user memory creation, create an Agent with Memory and a memory database, and set enable_user_memories=True.

Enabling user memory will also add all existing user memories to the agent’s system prompt.

1

User memory example

user_memory.py
from agno.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.google.gemini import Gemini
from agno.storage.sqlite import SqliteStorage

session_id = "session_1"
jon_hamm_id = "jon_hamm@example.com"

memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
memory = Memory(db=memory_db)

agent = Agent(
    model=Gemini(id="gemini-2.0-flash-exp"),
    memory=memory,
    storage=SqliteStorage(
        table_name="agent_sessions", db_file="tmp/persistent_memory.db"
    ),
    enable_user_memories=True,
)

agent.print_response(
    "My name is Jon Hamm and I like to hike in the mountains on weekends.",
    stream=True,
    user_id=jon_hamm_id,
    session_id=session_id,
)

agent.print_response(
    "What are my hobbies?", stream=True, user_id=jon_hamm_id, session_id=session_id
)

memories = memory.get_user_memories(user_id=jon_hamm_id)
print("Jon Hamm's memories:")
for i, m in enumerate(memories):
    print(f"{i}: {m.memory}")
2

Run the example

Install libraries

pip install google-genai agno

Export your key

export GOOGLE_API_KEY=xxx

Run the example

python user_memory.py

User memories are stored in the Memory object and persisted in the SqliteMemoryDb to be used across multiple users and multiple sessions.

Creating Session Summaries

To enable session summaries, set enable_session_summaries=True on the Agent.

1

Session summary example

session_summary.py
    from agno.agent import Agent
    from agno.memory.v2.db.sqlite import SqliteMemoryDb
    from agno.memory.v2.memory import Memory
    from agno.models.google.gemini import Gemini

    memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
    memory = Memory(db=memory_db)

    user_id = "jon_hamm@example.com"
    session_id = "1001"

    agent = Agent(
        model=Gemini(id="gemini-2.0-flash-exp"),
        memory=memory,
        enable_session_summaries=True,
    )

    agent.print_response(
        "What can you tell me about quantum computing?",
        stream=True,
        user_id=user_id,
        session_id=session_id,
    )

    agent.print_response(
        "I would also like to know about LLMs?",
        stream=True,
        user_id=user_id,
        session_id=session_id
    )

    session_summary = memory.get_session_summary(
        user_id=user_id, session_id=session_id
    )
    print(f"Session summary: {session_summary.summary}\n")
2

Run the example

Install libraries

pip install google-genai agno

Export your key

export GOOGLE_API_KEY=xxx

Run the example

python session_summary.py

Agentic Memory Management

You can also enable an agent to manage the user memories for you. Enable agentic memory management by setting enable_agentic_memory=True on the Agent.

Enabling agentic memory will also add all existing user memories to the agent’s system prompt.

1

Agentic memory management example

agentic_memory_management.py
from agno.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.google.gemini import Gemini

memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
memory = Memory(db=memory_db)

john_doe_id = "john_doe@example.com"

agent = Agent(
    model=Gemini(id="gemini-2.0-flash-exp"),
    memory=memory,
    enable_agentic_memory=True,
)

# The agent can add new memories to the user's memory
agent.print_response(
    "My name is John Doe and I like to hike in the mountains on weekends.",
    stream=True,
    user_id=john_doe_id,
)

agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)

# The agent can also remove all memories from the user's memory
agent.print_response(
    "Remove all existing memories of me. Completely clear the DB.",
    stream=True,
    user_id=john_doe_id,
)

agent.print_response(
    "My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id
)

# The agent can remove specific memories from the user's memory
agent.print_response("Remove any memory of my name.", stream=True, user_id=john_doe_id)

2

Run the example

Install libraries

pip install google-genai agno

Export your key

export GOOGLE_API_KEY=xxx

Run the example

python agentic_memory_management.py

Attributes

ParameterTypeDefaultDescription
memoryMemoryMemory()Agent’s memory object used for storing and retrieving information.
add_history_to_messagesboolFalseIf true, adds the chat history to the messages sent to the Model. Also known as add_chat_history_to_messages.
num_history_responsesint3Number of historical responses to add to the messages.
enable_user_memoriesboolFalseIf true, create and store personalized memories for the user.
enable_session_summariesboolFalseIf true, create and store session summaries.
enable_agentic_memoryboolFalseIf true, enables the agent to manage the user’s memory.

Developer Resources