Agno 支持使用 SqliteStorage 类将 Sqlite 作为 Agent 的存储后端。

用法

你需要提供 db_urldb_filedb_engine。以下示例使用了 db_file

sqlite_storage_for_agent.py
from agno.storage.sqlite import SqliteStorage

# 使用 Sqlite 数据库创建存储后端
storage = SqliteStorage(
    # 将 session 存储在 ai.sessions 表中
    table_name="agent_sessions",
    # db_file: Sqlite 数据库文件
    db_file="tmp/data.db",
)

# 将存储添加到 Agent
agent = Agent(storage=storage)

参数

参数类型默认值描述
table_namestr-要使用的表名。
schemaOptional[str]"ai"Schema 名称,默认为 "ai"。
db_urlOptional[str]None数据库 URL,如果提供的话。
db_engineOptional[Engine]None要使用的数据库引擎。
schema_versionint1Schema 的版本号,默认为 1。
auto_upgrade_schemaboolFalse如果为 true,则在必要时自动升级 schema。

开发者资源