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
- The agent writes SQL and runs it.
- It errors, or returns a number a human flags as wrong.
- The agent diagnoses the cause (wrong column, stale table, a join that double-counts).
- The fix is saved as a learning.
- 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),
),
)
| Mode | Behavior | Use for |
|---|
ALWAYS | Capture runs automatically after each response | Query-error corrections |
AGENTIC | The agent decides what is worth saving | Nuanced domain insights |
PROPOSE | The agent proposes, a human approves before it persists | Anything 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)
| Store | Why a data agent wants it |
|---|
| Learned Knowledge | Corrections that transfer across users |
| Decision Log | An audit trail of why a query shape changed |
Next steps
| Task | Guide |
|---|
| Feed it curated context too | Grounding in context |
| Gate writes behind approval | Safe data access |
Developer Resources