What is Memory?
Memory in Agno allows agents to:- Store and retrieve user preferences and personal information
- Maintain context across multiple conversations and sessions
- Build personalized experiences based on past interactions
- Share memories across multiple agents working with the same user
Key Components
MemoryManager
TheMemoryManager is responsible for creating, updating, and retrieving user memories. It uses an LLM to intelligently extract and manage memories from conversations.
UserMemory
UserMemory objects represent individual memories stored in the database:
Memory Workflow
from agno.agent import Agent
from agno.db.postgres import PostgresDb
agent = Agent(
db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
update_memory_on_run=True,
)
agent.print_response(
"My name is John Doe and I like hiking in the mountains",
user_id="[email protected]"
)
# Agent will remember the user's name and hobbies
agent.print_response(
"What are my hobbies?",
user_id="[email protected]"
)
Memory Storage
Memories are stored in a database and associated with:- user_id: Identifies which user the memory belongs to
- agent_id: Which agent created the memory (optional)
- team_id: Which team created the memory (optional)
- topics: Categories or tags for the memory
- updated_at: Timestamp of the last update
Multi-User Support
Agno’s memory system supports multiple users, with memories isolated byuser_id:
Memory Optimization
As conversations grow, you may need to optimize memories to reduce token usage. Agno provides optimization strategies:Next Steps
User Memories
Learn how to create, retrieve, and manage user memories
Session State
Manage conversation history and session summaries
Storage Overview
Choose the right database for your application
Database Adapters
Configure PostgreSQL, MongoDB, Redis, and more