cookbook/06_storage/postgres/README.md
Examples demonstrating PostgreSQL database integration with Agno agents, teams, and workflows.
uv pip install psycopg2-binary
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,
)
Agno also supports using your PostgreSQL database asynchronously, via the AsyncPostgresDb class:
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,
)
postgres_for_agent.py - Agent with PostgreSQL storagepostgres_for_team.py - Team with PostgreSQL storagepostgres_for_workflow.py - Workflow with PostgreSQL storage