Storage protocol and are injected into agents via the storage parameter.
Import
Storage Protocol
All storage backends implement this protocol:MemoryStorage
In-memory storage for development and testing. Data is lost when the process exits.Constructor
Usage
Notes
- Data is shared across all agents using the same
MemoryStorageinstance - Thread-safe for concurrent access
- Fast for development and testing
- Not suitable for production persistence
SQLiteStorage
Async SQLite persistence usingaiosqlite. Non-blocking database operations that won’t freeze your event loop.
Constructor
str
required
Path to the SQLite database file. Use
:memory: for in-memory database.Usage
Methods
sql
query: SQL query string with?placeholders*params: Query parameters
Notes
- Uses lazy connection initialization
- Connection is automatically closed when the agent stops
- Tables are created automatically on first use
- State and messages are stored as JSON
Creating Custom Storage Backends
Implement theStorage protocol to use any backend:
DynamoDB Example
PostgreSQL Example
Comparison
Choosing a Backend
- Development/Testing: Use
MemoryStorage- fast, no setup - Local Deployment: Use
SQLiteStorage- simple persistence, works out of box - Multi-Instance/Scaling: Create a custom backend with Redis, DynamoDB, or PostgreSQL
- Serverless: Create a custom backend with DynamoDB or other serverless databases