Storage
Agents use storage to persist sessions by storing them in a database.
Agents come with built-in memory but it only lasts while the session is active. To continue conversations across sessions, we store Agent sessions in a database, like PostgreSQL.
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.
Storage works with both agents, teams, and workflows. The storage system in Agno is versatile and can be used with both individual agents and complex workflows. This allows for persistent conversations and cached results across sessions.
Learn more about using storage with agents, workflows and teams to build powerful multi-agent systems with state management.
The general syntax for adding storage to an Agent looks like:
Example
Run Postgres
Install docker desktop and run Postgres on port 5532 using:
Create an Agent with Storage
Create a file agent_with_storage.py
with the following contents
Run the agent
Install libraries
Run the agent
Now the agent continues across sessions. Ask a question:
Then message bye
to exit, start the app again and ask:
Start a new run
Run the agent_with_storage.py
file with the --new
flag to start a new run.
Schema Upgrades
The relational SQL-based storage classes have fixed schemas. As new Agno features are released, the schemas might need to be updated.
Upgrades can either be done manually or automatically.
Automatic Upgrades
Automatic upgrades are done when the auto_upgrade_schema
parameter is set to True
in the storage class constructor.
You only need to set this once for an agent run and the schema would be upgraded.
Manual Upgrades
Manual schema upgrades can be done by calling the upgrade_schema
method on the storage class.
Params
Parameter | Type | Default | Description |
---|---|---|---|
storage | Optional[AgentStorage] | None | Storage mechanism for the agent. |
Developer Resources
- View Cookbook