> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 带记忆的 Agent

## 代码

```python cookbook/models/vllm/memory.py theme={null}
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
)
```

<Note>
  请确保 Postgres 数据库正在运行。
</Note>

## 使用方法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="启动 Postgres 数据库">
    ```bash theme={null}
    ./cookbook/scripts/run_pgvector.sh
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U agno openai vllm sqlalchemy psycopg[binary] pgvector
    ```
  </Step>

  <Step title="启动 vLLM 服务器">
    ```bash theme={null}
    vllm serve microsoft/Phi-3-mini-128k-instruct \
        --dtype float32 \
        --enable-auto-tool-choice \
        --tool-call-parser pythonic
    ```
  </Step>

  <Step title="运行 Agent">
    ```bash theme={null}
    python cookbook/models/vllm/memory.py
    ```
  </Step>
</Steps>
