> ## 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 Storage

> Persist chat history for a vLLM agent with PostgresDb.

## Code

```python db.py theme={null}
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.vllm import VLLM
from agno.tools.websearch import WebSearchTools

# Setup the database
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)

agent = Agent(
    model=VLLM(id="Qwen/Qwen2.5-7B-Instruct"),
    db=db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
)

agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
```

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

## Usage

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

**1. Install dependencies**

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

**2. Start Postgres database**

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

**3. Start vLLM server**

```bash theme={null}
vllm serve Qwen/Qwen2.5-7B-Instruct \
    --enable-auto-tool-choice \
    --tool-call-parser hermes \
    --dtype float16 \
    --max-model-len 8192 \
    --gpu-memory-utilization 0.9
```

**4. Set your API key**

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

**5. Run Agent**

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

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


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