A self-learning data agent inspired by OpenAI's in-house data agent.
Raw LLMs writing SQL hit a wall fast. They hallucinate column names, miss type quirks, and ignore the tribal knowledge that makes queries actually work. The problem isn't model capability, it's missing context.
Dash solves this with 6 layers of grounded context and a self-learning knowledge loop.
| Layer | What It Provides | Source |
|---|---|---|
| Table Metadata | Schema, columns, relationships | knowledge/tables/*.json |
| Business Rules | Metric definitions, gotchas | knowledge/business/*.json |
| Query Patterns | Validated SQL that works | knowledge/queries/*.sql |
| Institutional Knowledge | External docs, wikis | MCP (optional) |
| Memory | Patterns discovered through errors | Agno's LearningMachine |
| Runtime Context | Live schema when things change | introspect_schema tool |
The agent retrieves relevant context at query time via hybrid search, then generates SQL grounded in patterns that already work.
User Question
↓
Retrieve Context (schemas, patterns, gotchas)
↓
Generate SQL (grounded in working examples)
↓
Execute & Analyze
↓
┌───┴───┐
↓ ↓
Success Error
↓ ↓
Offer Learn
to save from it
When a query fails, the agent introspects the schema, fixes the issue, and saves the learning. Next time, it won't make the same mistake. No model retraining—just better retrieval knowledge.
git clone https://github.com/agno-agi/data-agent.git && cd data-agent
cp example.env .env # Add OPENAI_API_KEY
# Start
docker compose up -d --build
docker exec -it data-agent-api python -m da.scripts.load_data
docker exec -it data-agent-api python -m da.scripts.load_knowledge| Endpoint | URL |
|---|---|
| API | http://localhost:8000 |
| Docs | http://localhost:8000/docs |
| Control Plane | os.agno.com → Add OS → Local → http://localhost:8000 |
Try it (sample F1 dataset):
Who won the most F1 World Championships?
How many races has Lewis Hamilton won?
Compare Ferrari vs Mercedes points 2015-2020
The knowledge base stores what makes your data unique, the context an LLM can't infer from schema alone.
knowledge/
├── tables/ # What each table contains
├── queries/ # SQL patterns that work
└── business/ # How your org talks about data
Describe tables beyond what's in the schema:
{
"table_name": "orders",
"table_description": "Customer orders with line items denormalized",
"use_cases": ["Revenue reporting", "Customer analytics"],
"data_quality_notes": [
"created_at is UTC",
"status can be: pending, completed, refunded",
"amount is in cents, not dollars"
]
}Validated SQL the agent can learn from:
-- <query name>monthly_revenue</query name>
-- <query description>
-- Monthly revenue calculation.
-- Handles: cents to dollars, excludes refunds
-- </query description>
-- <query>
SELECT
DATE_TRUNC('month', created_at) AS month,
SUM(amount) / 100.0 AS revenue_dollars
FROM orders
WHERE status = 'completed'
GROUP BY 1
ORDER BY 1 DESC
-- </query>Map organizational language to data:
{
"metrics": [
{"name": "MRR", "definition": "Sum of active subscription amounts, excluding trials"},
{"name": "Churn", "definition": "Subscriptions cancelled / total subscriptions at period start"}
],
"common_gotchas": [
{"issue": "Revenue double-counting", "solution": "Use completed orders only, not pending"}
]
}python -m da.scripts.load_knowledge # Upsert changes
python -m da.scripts.load_knowledge --recreate # Fresh start./scripts/venv_setup.sh && source .venv/bin/activate
docker compose up -d data-agent-db
python -m da.scripts.load_data
python -m da # CLI moderailway login && ./scripts/railway_up.sh| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
Yes | OpenAI API key |
EXA_API_KEY |
No | Web search for institutional knowledge |
DB_* |
No | Database config (defaults to localhost) |
- OpenAI's In-House Data Agent — the inspiration
- Self-Improving SQL Agent — deep dive on an earlier architecture
- Agno Docs
- Discord