from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses
from agno.tools.sql import SQLTools
from sqlalchemy import create_engine
warehouse_url = "postgresql+psycopg://readonly@warehouse/analytics"
readonly_engine = create_engine(
warehouse_url,
connect_args={"options": "-c default_transaction_read_only=on"},
)
agent = Agent(
model=OpenAIResponses(id="gpt-5.5"),
db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
tools=[SQLTools(db_engine=readonly_engine)],
instructions=(
"Introspect the schema before writing SQL. Answer with the numbers "
"and the exact query you ran. Never guess a column name. Pass "
"limit=None to run_sql_query when the answer needs every row."
),
)
agent.print_response("How many active subscriptions are on the Pro plan?")