from agno.agent import Agent
from agno.models.litellm import LiteLLM
from agno.storage.sqlite import SqliteStorage
from agno.tools.duckduckgo import DuckDuckGoTools
# 使用 Sqlite 数据库创建存储后端
storage = SqliteStorage(
# 将会话存储在 ai.sessions 表中
table_name="agent_sessions_storage",
# db_file: Sqlite 数据库文件
db_file="tmp/data.db",
)
# 向代理添加存储
agent = Agent(
model=LiteLLM(id="gpt-4o"),
storage=storage,
tools=[DuckDuckGoTools()],
add_history_to_messages=True,
)
agent.print_response("有多少加拿大人?")
agent.print_response("他们的国歌叫什么名字?")
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
设置您的 API 密钥
export LITELLM_API_KEY=xxx
安装库
pip install -U litellm openai agno
运行代理
python cookbook/models/litellm/storage.py