Agentic analytics
What agentic analytics is, why connecting an agent straight to the warehouse fails, and the five layers that make it trustworthy.
What is agentic analytics?
Agentic analytics is an operating model in which people delegate analytical work to AI agents while retaining judgment and control. An agent can clarify a business question, plan an investigation, gather relevant context, query governed data, explain its findings, and identify uncertainty.
This is broader than chat with your data or text-to-SQL. Those approaches focus on generating a query from a prompt. Real analytical work also requires business definitions, context, review, evaluation, and a reasoning path that someone can inspect.
The model is rarely the problem. The system underneath the agent is. A chat box is easy to copy; the system underneath is the product.
Why agent → warehouse fails
With MCP, connecting an LLM to your data warehouse takes one sentence. Ask it "What was our revenue last month?" in four fresh chats and you can get four different numbers, each one confident and nicely formatted, and none of them the number Finance reports. The chats convert no currencies, keep voided invoices and test accounts, count tax as revenue, book annual plans in the month they're invoiced, or read from a deprecated table. None of them asks which revenue you mean.
Analytics is a stress test for agents: the action space is unbounded (raw SQL), the intent is ambiguous ("which revenue?"), and there's no built-in ground truth to check against. A direct connection fails in five ways:
| # | Failure | What happens | In agent terms |
|---|---|---|---|
| F1 | Schema ≠ meaning | "Revenue" can mean gross, net, recognized, invoiced, or collected cash. The agent picks one. | It guesses intent from column names. |
| F2 | Unbounded actions | Joins and metric logic are rebuilt in every prompt, so answers drift. | Raw SQL is too large a tool surface. |
| F3 | No verification | Plausible but wrong numbers, and a polished chart makes people trust them. | Nothing tells the agent or the user that the answer is wrong. |
| F4 | No reviewed state | The answer lives in one person's chat thread. Nothing is versioned, reviewed, or shared. | There's no durable state humans can review. |
| F5 | No learning | Every fresh chat starts from zero and repeats the same mistakes. | Failures don't improve the system. |
This has happened before. Spreadsheets, self-service BI, and ad-hoc SQL each promised that anyone could do analytics, and each one produced competing versions of the truth until a constraint made it safe: a governed semantic layer. Agents need the same constraint, plus a few more.
The five layers
A trustworthy agentic analytics system has five layers. Each one does a different job and fixes one of the failures above.
- Answer time · every question
- Change time · reviewed
- “What was our revenue last month?”
- L3 Context working memory: what the agent knows now
- Agent LLM + context window
- L1 Semantic layer interface: what the agent can do
- Warehouse — Raw tables
- L4 Evals verification: scores every step
- L5 Learning loop improvement: opens PRs
- Data team reviews and merges every PR
- L2 Source of truth versioned state: what is true. The agent proposes, humans merge
- question → agent
- agent → l3 (reads)
- l3 → agent (injects)
- agent → l1 (calls)
- l1 → agent (results)
- l1 → warehouse (SQL)
- agent → warehouse (raw SQL: skips every layer)
- agent → l4 (trace)
- l4 → l5 (failures)
- l5 → l2 (opens a PR)
- team → l2 (approves)
- l2 → l3 (indexed)
- l2 → l1 (deploys on merge)
| Layer | Role | Fixes | How |
|---|---|---|---|
| L1 Semantic layer | Interface: what the agent can do | F2 Unbounded actions | Typed tools on governed metrics. Logic is defined once, not per prompt. |
| L2 Source of truth | Versioned state: what is true | F4 No reviewed state | Definitions live in Git. Every change is a pull request that a human reviews. |
| L3 Context | Working memory: what the agent knows now | F1 Schema ≠ meaning | Notes on metrics, tables, and incidents say what things mean here. |
| L4 Evals | Verification: scores every step | F3 No verification | Every step is scored, so a wrong step is caught even without the right answer. |
| L5 Learning loop | Improvement: turns failures into changes | F5 No learning | Failures and overrides become pull requests, so the next chat starts smarter. |
The layers work at two different times:
- At answer time, on every question, the agent calls the semantic layer (L1), reads the context attached to what it touches (L3), and is scored by evals (L4). It never sends raw SQL to the warehouse.
- At change time, the learning loop (L5) proposes changes as pull requests to the source of truth (L2). The data team reviews and merges them, and the merged changes deploy to the semantic layer and context the agent uses.
L1 Semantic layer: the agent's tool interface
The semantic layer defines governed metrics, dimensions, and relationships and exposes them to the agent as tools. Instead of writing SQL against raw tables, the agent queries a metric by name:
query_metric("net_revenue", period="2026-09", compare="previous_month")The semantic layer compiles the SQL; the agent never writes it. That gives the agent a smaller, typed action space with fewer ways to be wrong, and the same question returns the same number in every session.
The agent must go through the semantic layer and not bypass it with raw SQL when that's convenient. Otherwise it recreates the problem that self-service BI had to solve. The framework works with any semantic layer, such as dbt Semantic Layer, Cube, LookML, or anfra.
L2 Source of truth: versioned state
The source of truth is a Git repository that agents can read and humans can review. It holds the semantic-layer code, transformation code, a wiki of business definitions and decisions, and eval cases:
analytics/
├─ metrics/revenue.aml semantic layer
├─ models/fct_revenue.sql transformations
├─ wiki/
│ ├─ metrics/revenue.md definitions
│ ├─ data/deprecations.md
│ └─ incidents/INC-2291.md
└─ evals/cases.yaml eval casesAgents need files they can read and diffs humans can review. A semantic layer that lives only in a GUI is hard for an agent to inspect or change.
The system is human-in-the-loop by default: the agent proposes changes as pull requests and never changes production logic silently. One reviewed file, with an owner and a history, replaces many unreviewed definitions scattered across chat threads.
L3 Context: working memory
A schema says what exists. Context says what it means here: which revenue is official, which table is deprecated, which incident affected last month's numbers.
| Schema | Context |
|---|---|
| Three tables with revenue-like columns | Unqualified "revenue" means Net Revenue. Board reporting uses it. |
rpt_revenue_monthly | Deprecated. Gross list price, no longer maintained. Don't use it. |
September rows in credit_notes | Incident INC-2291: an outage on 9 September led to SLA credits that reduce September revenue. |
Context isn't a document dump into a vector store. Stale context confuses the agent, too much adds noise, and too little misses assumptions. Instead:
- Attach context to things: metrics, tables, teams, time periods, and incidents.
- Select what the question needs by following what the question touches.
- Expire what's stale, such as an incident that has since been fixed.
The goal is organizational memory the agent can use, not just retrieval.
L4 Evals: verification at every step
Without evals, agentic analytics is a demo. With evals, it's engineering.
A final-answer eval needs ground truth, which analytics rarely has. Step evals don't: you don't need the right answer to catch a wrong step. Evaluate each step of the workflow:
| Step | What to check |
|---|---|
| Interview | Did the agent ask for clarification when the question was ambiguous? |
| Plan | Did it choose the right metrics, dimensions, and segments, and state its assumptions? |
| Context | Was the context it used relevant and current? |
| Modeling | Are new definitions correct, reusable, and consistent with conventions? |
| Query | Did it go through the semantic layer? Did it handle currencies, tax, voided records, test accounts, join fan-out, and revenue recognition? |
| Presentation | Did it cite assumptions, avoid overclaiming, and keep correlation separate from causation? |
An answer can pass most checks and still be far off, so score every step, not only the final number. Build the eval set from real questions and analyst corrections: each mistake someone actually made becomes an eval case. This is the analytics version of tests, CI, code review, and monitoring.
L5 Learning loop: the agent as a sensor
The agent is a sensor as well as a consumer. Its usage shows where the system's knowledge is missing:
| Signal | Change |
|---|---|
| The same question keeps coming up | Make it a dashboard. |
| The agent keeps struggling with a metric | Clarify the definition. |
| Users keep correcting an explanation | Add what's missing to the wiki. |
| Analysts keep overriding the plan | Add eval cases. |
Each change goes to the source of truth as a pull request for a human to review. For example, if most unqualified "revenue" questions end up as Net Revenue, the agent can propose making Net Revenue the default for that term, and Finance approves or rejects the change. The system gets better with use, without retraining any model.
One question, end to end
Here is how a governed agent answers "What was our revenue last month?":
- Find the metric:
search_metrics("revenue")returns the governed metrics, such as Net Revenue (owned by Finance), Bookings, and Cash Collected. (L1, L2) - Find the context:
search_context(...)finds the notes that say which revenue is official, which table is deprecated, and which incident affected the period. (L3, L2) - Interview: "Revenue" means three different things here, so the agent states Finance's definition and asks which one you mean. (L4)
- Query:
query_metric("net_revenue", ...). The semantic layer generates the SQL. (L1) - Explain:
explain_changebreaks the change into new, churned, and existing customers and credit notes. (L1, L3) - Present: the number and its trend, with assumptions, caveats, and links to the definitions it used. (L2)
- Evaluate:
evals.run(trace)scores every step of the run. (L4) - Learn:
log_feedback()records the outcome and, when a pattern emerges, opens a pull request for the metric owner. (L5, L2) - Ask again: a fresh session returns the same number. (L1)
The value isn't that the agent does every step on its own. Every step is explicit, inspectable, and evaluated.
Principles beyond analytics
The same blueprint applies to any domain where agents need to be trusted:
- Shrink the action space. Give the agent governed, typed tools instead of a raw interface such as SQL, a shell, or an API.
- Make state inspectable. Use files, diffs, and pull requests so humans can review what the agent changes.
- Engineer context; don't dump it. Attach knowledge to the things it describes.
- Evaluate each step, not just the final answer.
- Treat the agent as a sensor. Its failures show where your system's knowledge is missing.
In the self-service era, data teams modeled data so humans could explore. In the agentic era, they model data, context, and evals so humans and agents build trusted analytics together.
How anfra fits
anfra is in active development. It covers the first three layers today, though none of them is complete yet. The last two are planned.
- Answer time · every question
- Change time · reviewed
- “What was our revenue last month?”
- L3 Context available, still evolving
- Agent LLM + context window
- L1 Semantic layer available, still evolving
- Warehouse — Raw tables
- L4 Evals planned
- L5 Learning loop planned
- Data team reviews and merges every PR
- L2 Source of truth available, still evolving
- question → agent
- agent → l3 (reads)
- l3 → agent (injects)
- agent → l1 (calls)
- l1 → agent (results)
- l1 → warehouse (SQL)
- agent → warehouse (raw SQL: skips every layer)
- agent → l4 (trace)
- l4 → l5 (failures)
- l5 → l2 (opens a PR)
- team → l2 (approves)
- l2 → l3 (indexed)
- l2 → l1 (deploys on merge)
| Layer | Status in anfra |
|---|---|
| L1 Semantic layer | Available, still evolving. Every agent and application queries business data through the same governed language. See the building blocks below. |
| L2 Source of truth | Available, still evolving. Definitions live in a code-native project: files that agents can read and humans can review. |
| L3 Context | Available, still evolving. The Semantic Catalog brings definitions, documentation, ownership, and lineage from your semantic layer, dbt, and LookML projects into one place agents can search. |
| L4 Evals | Planned. |
| L5 Learning loop | Planned. |
An anfra semantic project uses four core building blocks:
- Data models map warehouse tables or SQL queries into dimensions and measures.
- Datasets combine related data models into governed, queryable views.
- Metrics define named, reusable calculations such as revenue or active users.
- Dimensions define how metrics can be grouped and filtered, such as by date, plan, or country.