Code
cookbook/11_models/cohere/db.py
Copy
Ask AI
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.cohere import Cohere
from agno.tools.hackernews import HackerNewsTools
# Setup the database
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
agent = Agent(
model=Cohere(id="command-a-03-2025"),
db=db,
tools=[HackerNewsTools()],
add_history_to_context=True,
)
agent.print_response("How many people live in Canada?")
agent.print_response("What is their national anthem called?")
Usage
1
Set up your virtual environment
Copy
Ask AI
uv venv --python 3.12
source .venv/bin/activate
2
Set your API key
Copy
Ask AI
export CO_API_KEY=xxx
3
Install dependencies
Copy
Ask AI
uv pip install -U sqlalchemy cohere agno
4
Run PgVector
Copy
Ask AI
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:16
5
Run Agent
Copy
Ask AI
python cookbook/11_models/cohere/db.py