from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.knowledge.knowledge import Knowledge
from agno.learn import LearningMachine
from agno.models.openai import OpenAIResponses
from agno.tools.sql import SQLTools
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
knowledge = Knowledge(
vector_db=PgVector(table_name="agent_learnings", db_url=db_url),
)
agent = Agent(
id="data-analyst",
model=OpenAIResponses(id="gpt-5.5"),
db=db,
tools=[SQLTools(db_url="postgresql+psycopg://readonly@warehouse/analytics")],
learning=LearningMachine(knowledge=knowledge, decision_log=True),
instructions=(
"Before writing SQL, call search_learnings with terms from the request and "
"apply relevant corrections. "
"When a query errors, diagnose the cause. Call save_learning for a "
"reusable correction. Call log_decision when you change the query shape."
),
)