Code
db.py
Ensure Postgres database is running.
Usage
1
Set up your virtual environment
2
Install dependencies
3
Start Postgres database
4
Start vLLM server
5
Set your API key
6
Run Agent
Save the code above as
db.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Persist chat history for a vLLM agent with PostgresDb.
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?")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai vllm sqlalchemy psycopg ddgs
Start Postgres database
./cookbook/scripts/run_pgvector.sh
Start vLLM server
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
Set your API key
export VLLM_API_KEY=xxx
Run Agent
db.py, then run:python db.py
Was this page helpful?