Code

cookbook/tools/postgres_tools.py
from agno.agent import Agent
from agno.tools.postgres import PostgresTools

agent = Agent(
    tools=[PostgresTools(db_url="postgresql://user:pass@localhost:5432/db")],
    show_tool_calls=True,
    markdown=True,
)
agent.print_response("Show me all tables in the database")

Usage

1

Create a virtual environment

Open the Terminal and create a python virtual environment.

python3 -m venv .venv
source .venv/bin/activate
2

Set your API key

export OPENAI_API_KEY=xxx
3

Set your database URL

export DATABASE_URL=postgresql://user:pass@localhost:5432/db
4

Install libraries

pip install -U psycopg2-binary sqlalchemy openai agno
5

Run Agent

python cookbook/tools/postgres_tools.py