from agno.agent import Agent
from agno.memory.v2.db.postgres import PostgresMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.vllm import vLLM
from agno.storage.postgres import PostgresStorage
DB_URL = "postgresql+psycopg://ai:ai@localhost:5532/ai"
agent = Agent(
model=vLLM(id="microsoft/Phi-3-mini-128k-instruct"),
memory=Memory(
db=PostgresMemoryDb(table_name="agent_memory", db_url=DB_URL),
),
enable_user_memories=True,
enable_session_summaries=True,
storage=PostgresStorage(
table_name="personalized_agent_sessions",
db_url=DB_URL,
),
)
# 分享个人信息;Agent 应该能够记住它们。
agent.print_response("My name is John Billings.", stream=True)
print("Current memories →")
pprint(agent.memory.memories)
print("Current summary →")
pprint(agent.memory.summaries)
agent.print_response("I live in NYC.", stream=True)
print("Memories →")
pprint(agent.memory.memories)
print("Summary →")
pprint(agent.memory.summaries)
agent.print_response("I'm going to a concert tomorrow.", stream=True)
print("Memories →")
pprint(agent.memory.memories)
print("Summary →")
pprint(agent.memory.summaries)
# 让 Agent 回忆信息
agent.print_response(
"What have we been talking about, do you know my name?", stream=True
)
请确保 Postgres 数据库正在运行。
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
启动 Postgres 数据库
./cookbook/scripts/run_pgvector.sh
安装库
pip install -U agno openai vllm sqlalchemy psycopg[binary] pgvector
启动 vLLM 服务器
vllm serve microsoft/Phi-3-mini-128k-instruct \
--dtype float32 \
--enable-auto-tool-choice \
--tool-call-parser pythonic
运行 Agent
python cookbook/models/vllm/memory.py