Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agno.com/llms.txt

Use this file to discover all available pages before exploring further.

When an agent gets a query wrong, the fix shouldn’t live in your head. Agno’s LearningMachine diagnoses the error, saves the correction as a learning, and pulls it back into context the next time a similar question comes in.
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses
from agno.tools.sql import SQLTools

agent = Agent(
    model=OpenAIResponses(id="gpt-5.5"),
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
    tools=[SQLTools(db_url="postgresql+psycopg://readonly@warehouse/analytics")],
    learning=True,
    instructions="When a query errors, diagnose the cause and record the correction.",
)
learning=True enables capture and recall. The agent accumulates corrections across runs and pulls the relevant ones into context on future questions.

The loop

  1. The agent writes SQL and runs it.
  2. It errors, or returns a number a human flags as wrong.
  3. The agent diagnoses the cause (wrong column, stale table, a join that double-counts).
  4. The fix is saved as a learning.
  5. The next similar question retrieves that learning before generating SQL.
Each diagnosed error is written down and pulled back before the next similar query, so recurring errors stop recurring: the agent accumulates what your warehouse’s sharp edges are.

Choose how learning happens

Each store takes a mode. For a data agent, you usually want errors captured automatically and schema changes proposed for review.
from agno.learn import LearningMachine, LearningMode, UserMemoryConfig

agent = Agent(
    model=OpenAIResponses(id="gpt-5.5"),
    db=db,
    learning=LearningMachine(
        user_memory=UserMemoryConfig(mode=LearningMode.ALWAYS),
    ),
)
ModeBehaviorUse for
ALWAYSCapture runs automatically after each responseQuery-error corrections
AGENTICThe agent decides what is worth savingNuanced domain insights
PROPOSEThe agent proposes, a human approves before it persistsAnything that changes how numbers are computed

Audit what it learned

A data agent’s learnings change the numbers it reports, so they need to be inspectable. Read the Learned Knowledge store to see the corrections it captured, and the Decision Log for the reasoning behind a changed query shape.
lm = agent.learning_machine

# What the agent has learned about the warehouse:
lm.learned_knowledge_store.print(query="MRR")

# The audit trail of why a query shape changed:
lm.decision_log_store.print(agent_id=agent.id, limit=5)
StoreWhy a data agent wants it
Learned KnowledgeCorrections that transfer across users
Decision LogAn audit trail of why a query shape changed

Next steps

TaskGuide
Feed it curated context tooGrounding in context
Gate writes behind approvalSafe data access

Developer Resources