Back to Agno

PostgreSQL Integration

cookbook/06_storage/postgres/README.md

2.6.41.0 KB
Original Source

PostgreSQL Integration

Examples demonstrating PostgreSQL database integration with Agno agents, teams, and workflows.

Setup

shell
uv pip install psycopg2-binary

Configuration

python
from agno.agent import Agent
from agno.db.postgres import PostgresDb

db = PostgresDb(db_url="postgresql+psycopg://username:password@localhost:5432/database")

agent = Agent(
    db=db,
    add_history_to_context=True,
)

Async usage

Agno also supports using your PostgreSQL database asynchronously, via the AsyncPostgresDb class:

python
from agno.agent import Agent
from agno.db.postgres import AsyncPostgresDb

db = AsyncPostgresDb(db_url="postgresql+psycopg://username:password@localhost:5432/database")

agent = Agent(
    db=db,
    add_history_to_context=True,
)

Examples