Agno 支持使用 Redis 作为 Agent 的存储后端,通过 RedisStorage 类。

用法

运行 Redis

安装 docker desktop 并使用以下命令在端口 6379 上运行 Redis

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

# 初始化 Redis 存储,使用默认的本地连接
storage = RedisStorage(
    # 用于 Redis 键的前缀,为会话提供命名空间
    prefix="agno_test",
    # Redis 主机地址
    host="localhost",
    # Redis 端口号
    port=6379,
)

# 使用 Redis 存储创建 Agent
agent = Agent(
    storage=storage,
)

参数

参数类型描述默认值
prefixstr用于 Redis 键的 prefix,以 namespace 会话Required
hoststrRedis host 地址"localhost"
portintRedis 端口号6379
dbintRedis 数据库号0
passwordOptional[str]需要 authentication 时的 Redis passwordNone
modeOptional[Literal["agent", "team", "workflow"]]Storage mode"agent"

开发者资源