Agno supports using Redis as a storage backend for Agents using the RedisStorage
class.
Usage
Run Redis
Install docker desktop and run Redis on port 6379 using:
docker run --name my-redis -p 6379:6379 -d redis
redis_storage_for_agent.py
from agno.agent import Agent
from agno.storage.redis import RedisStorage
from agno.tools.duckduckgo import DuckDuckGoTools
# Initialize Redis storage with default local connection
storage = RedisStorage(
prefix="agno_test", # Prefix for Redis keys to namespace the sessions
host="localhost", # Redis host address
port=6379, # Redis port number
)
# Create agent with Redis storage
agent = Agent(
storage=storage,
tools=[DuckDuckGoTools()],
add_history_to_messages=True,
)
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
# Verify storage contents
print("\nVerifying storage contents...")
all_sessions = storage.get_all_sessions()
print(f"Total sessions in Redis: {len(all_sessions)}")
if all_sessions:
print("\nSession details:")
session = all_sessions[0]
print(f"Session ID: {session.session_id}")
print(f"Messages count: {len(session.memory['messages'])}")
Params
Parameter | Type | Description | Default |
---|
prefix | str | Prefix for Redis keys to namespace the sessions | Required |
host | str | Redis host address | "localhost" |
port | int | Redis port number | 6379 |
db | int | Redis database number | 0 |
password | Optional[str] | Redis password if authentication is required | None |
mode | Optional[Literal["agent", "team", "workflow"]] | Storage mode | "agent" |
Developer Resources