from agno.agent import Agent
from agno.memory.agent import AgentMemory
from agno.memory.db.postgres import PgMemoryDb
from agno.models.openai import OpenAIChat
from agno.playground import Playground
from agno.storage.agent.sqlite import SqliteAgentStorage
from agno.storage.postgres import PostgresStorage
agent_storage_file: str = "tmp/agents.db"
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
basic_agent = Agent(
name="Basic Agent",
model=OpenAIChat(id="gpt-4o"),
memory=AgentMemory(
db=PgMemoryDb(
table_name="agent_memory",
db_url=db_url,
),
# 为此用户创建并存储个性化记忆
create_user_memories=True,
# 每次运行后更新用户的记忆
update_user_memories_after_run=True,
# 创建并存储会话摘要
create_session_summary=True,
# 每次运行后更新会话摘要
update_session_summary_after_run=True,
),
storage=PostgresStorage(
table_name="agent_sessions", db_url=db_url, auto_upgrade_schema=True
),
add_history_to_messages=True,
num_history_responses=3,
add_datetime_to_instructions=True,
markdown=True,
)
playground = Playground(
agents=[
basic_agent,
],
name="Basic Agent",
description="A playground for basic agent",
app_id="basic-agent",
)
app = playground.get_app()
if __name__ == "__main__":
playground.serve(app="basic:app", reload=True)
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
设置您的 API 密钥
export OPENAI_API_KEY=xxx
安装库
pip install -U agno "uvicorn[standard]" openai psycopg-binary
运行 Agent
python cookbook/apps/playground/basic.py