from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.models.openai import OpenAIResponses
from agno.tools.sql import SQLTools
from agno.vectordb.pgvector import PgVector
knowledge = Knowledge(
vector_db=PgVector(table_name="dash_knowledge", db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
)
knowledge.insert(
name="Active subscriptions",
text_content=(
"Business rule: a subscription is active when ended_at IS NULL. "
"Validated query pattern: SELECT plan, count(*) FROM subscriptions "
"WHERE ended_at IS NULL GROUP BY plan."
),
)
agent = Agent(
model=OpenAIResponses(id="gpt-5.5"),
tools=[SQLTools(db_url="postgresql+psycopg://readonly@warehouse/analytics")],
knowledge=knowledge,
search_knowledge=True,
instructions="Retrieve relevant query patterns and table notes before writing SQL.",
)
agent.print_response("How many active subscriptions are on the Pro plan?")