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

# Agent with Memory

> Persist memories and session summaries for a vLLM agent with PostgresDb.

## Code

```python memory.py theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.vllm import VLLM
from rich.pretty import pprint

# Change this if your Postgres container is running elsewhere
DB_URL = "postgresql+psycopg://ai:ai@localhost:5532/ai"

agent = Agent(
    model=VLLM(id="microsoft/Phi-3-mini-128k-instruct"),
    db=PostgresDb(db_url=DB_URL),
    update_memory_on_run=True,
    enable_session_summaries=True,
)

# -*- Share personal information
agent.print_response("My name is john billings?", stream=True)
# -*- Print memories and summary
if agent.db:
    pprint(agent.get_user_memories(user_id="test_user"))
    pprint(
        agent.get_session(session_id="test_session").summary  # type: ignore
    )

# -*- Share personal information
agent.print_response("I live in nyc?", stream=True)
# -*- Print memories and summary
if agent.db:
    pprint(agent.get_user_memories(user_id="test_user"))
    pprint(
        agent.get_session(session_id="test_session").summary  # type: ignore
    )

# -*- Share personal information
agent.print_response("I'm going to a concert tomorrow?", stream=True)
# -*- Print memories and summary
if agent.db:
    pprint(agent.get_user_memories(user_id="test_user"))
    pprint(
        agent.get_session(session_id="test_session").summary  # type: ignore
    )

# Ask about the conversation
agent.print_response(
    "What have we been talking about, do you know my name?", stream=True
)
```

> [!NOTE]
>
> Ensure Postgres database is running.

## Usage

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

**1. Start Postgres database**

```bash theme={null}
./cookbook/scripts/run_pgvector.sh
```

**2. Install dependencies**

```bash theme={null}
uv pip install -U agno openai vllm sqlalchemy psycopg pgvector
```

**3. Start vLLM server**

```bash theme={null}
vllm serve microsoft/Phi-3-mini-128k-instruct \
    --dtype float32 \
    --enable-auto-tool-choice \
    --tool-call-parser pythonic
```

**4. Set your API key**

```bash theme={null}
export VLLM_API_KEY=xxx
```

**5. Run Agent**

Save the code above as `memory.py`, then run:

```bash theme={null}
python memory.py
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.