AskMetrics Guide¶
Overview¶
ask_metrics is a built-in metric question-answering subagent that can package a specific business context and tool surface for selected users. It answers questions from existing semantic metrics; Dosi compiles and executes the query. The main chat also provides metric queries and attribution directly. Choose AskMetrics when you want its scoped context or explicitly selected agent interface.
Use AskMetrics when the user asks for:
- KPI values, such as "What was revenue last month?"
- Metric trends, such as "How did shipped quantity change by month?"
- Grouped metric results, such as "Revenue by region for Q1"
- Metric attribution, such as "Which customer segment drove the revenue drop?"
AskMetrics is intentionally narrow. If no existing metric can answer the question, it says so directly and does not fall back to raw SQL.
Prerequisites¶
AskMetrics needs executable semantic metrics on the current datasource. Dosi is built in. See Dosi Semantic Engine for model discovery.
Metrics can come from existing OSI models or from the semantic_modeling subagent. After semantic_modeling successfully returns generated, it validates the target YAML and syncs the metrics to the Knowledge Base. They are immediately available on the same datasource without a manual publish, import, or Datus restart.
A metric subject tree is optional, but recommended because AskMetrics uses it as a routing catalog before searching.
Quick Start: Query Newly Generated Metrics¶
Continue from the DuckDB example in Semantic Modeling and start Datus with the same datasource:
After creating the bank_failures model, ask directly in the main chat, which can query the metrics itself:
AskMetrics matches the business wording against the subject tree and metric definitions, selecting the generated bank_failure_count and failed_assets_million metrics without requiring the user to know their names. This query uses yearly date buckets. The real test returned 14 yearly groups; for example, 2008 returned 26 and 768576.8, while 2024 returned 2 and 6107.8.
If /agent semantic_modeling was used to make the authoring agent current, return to the main chat first:
To route one question explicitly, use an agent reference:
For several consecutive metric questions, select AskMetrics first and then enter normal messages:
The legacy /ask_metrics <question> form is no longer supported. Web/API callers can route directly by using subagent_id: "ask_metrics".
AskMetrics is scoped to the current datasource. If the user asks for another datasource, switch datasource first and ask again.
How It Works¶
AskMetrics follows a metric-first workflow:
graph LR
A[User metric question] --> B[Match subject tree]
B --> C{Direct metric match?}
C -->|Yes| D[Use metric name and path]
C -->|No| E[Search metrics]
D --> F[Get dimensions when needed]
E --> F
F --> G[Query metrics]
G --> H{Attribution question?}
H -->|Yes| I[Run attribution analysis]
H -->|No| J[Return Markdown answer]
I --> J
Key behavior:
- Direct subject-tree matches are preferred over search.
search_metricsis used only when the subject tree is missing, partial, or ambiguous.get_metricis called for each metric before it is queried. It states how the metric is computed (expr), the datasets it reads and can be grouped by, its parameters, and its time grains.get_datasetis called for every dataset a query reads. Dataset and field descriptions hold conventions every query on it follows, such as a snapshot's version day or what a code value means.- Grouping and filtering names are
dataset.field, with the field nameget_datasetshows. query_metricsis the primary tool for metric values.- Change explanation and contribution questions use
attribute_metricsto split a change over the inputs of the metric's formula, andattribute_dimensionsto split it over the groups of one or more dimensions (one call per dimension to compare dimensions; several dimensions in one call drill down in order). - Raw SQL tools are not part of the default AskMetrics surface.
Default Tools¶
| Tool | Purpose |
|---|---|
context_search_tools.search_metrics |
Find candidate metrics when direct subject-tree matching is not enough |
context_search_tools.list_subject_tree |
List metric subject paths when the startup subject tree is too large to inline |
semantic_tools.list_metrics |
Enumerate executable metrics from Dosi |
semantic_tools.get_metric |
Describe one metric: how it is computed, the datasets it reads and can be grouped by, its parameters, and its time grains |
semantic_tools.get_dataset |
Describe one dataset: its fields with their definitions, fixed fields, time field, and relationships |
semantic_tools.query_metrics |
Query metric values |
semantic_tools.attribute_metrics |
Explain a metric's change through its formula: how much each input contributed |
semantic_tools.attribute_dimensions |
Explain a metric's change by the groups of its dimensions: how much each group contributed |
filesystem_tools.read_file |
Read relevant project business definitions or background |
filesystem_tools.glob |
Locate relevant project files |
filesystem_tools.grep |
Search project files for specific business terms |
File exploration is optional for any question when business scope or interpretation needs more context. AskMetrics first reuses supplied knowledge and metric/dataset descriptions; a simple query with enough context proceeds without a file lookup. Attribution may benefit from business definitions or operational records, but does not require a file-discovery step. When using project documents, AskMetrics cites their paths and distinguishes measured contributions from business hypotheses.
If the Dosi runtime is unavailable, AskMetrics cannot safely answer metric questions. If context search is unavailable, AskMetrics can still query Dosi, but it will not have subject-tree routing context.
Output¶
AskMetrics returns a concise Markdown report with:
- the interpreted question and time range
- the metric names used
- the result values from metric tools
- attribution findings when attribution was run
- limitations when the question cannot be answered with existing metrics
It does not return raw SQL and does not invent metric values.
Configuration¶
The built-in ask_metrics subagent works once the current datasource has executable metrics. You can override its model and turn budget:
Custom AskMetrics Agents¶
Use type: ask_metrics to create a custom metric QA agent with its own name, prompt template, or tool allowlist:
agent:
agentic_nodes:
sales_metric_qa:
type: ask_metrics
model: claude
max_turns: 100
prompt_version: "1.0"
tools: "context_search_tools.search_metrics,semantic_tools.get_metric,semantic_tools.query_metrics"
subject_tree_prompt_limit: 50
agent_description: "Answer sales metric questions using the sales semantic layer."
When system_prompt is omitted, Datus first looks for a prompt template matching the custom agent name, such as sales_metric_qa_system_1.0.j2, then falls back to the built-in ask_metrics_system template.
tools can be a comma-separated string or a list. An explicit allowlist replaces the defaults; the three file tools are not appended automatically. To enable project-file access in an existing custom allowlist, add the desired filesystem_tools.read_file, filesystem_tools.glob, and filesystem_tools.grep entries alongside its metric tools. Custom agents can also opt into other user-facing tool categories when needed.
For existing custom tool lists, remove context_search_tools.get_metrics. Use semantic_tools.get_metric when the metric definition is needed; context_search_tools.search_metrics remains available for discovery.
When Not To Use AskMetrics¶
Use another subagent when the task is not answerable through existing semantic metrics:
| Need | Use |
|---|---|
| Generate new Dosi metric definitions from SQL | semantic_modeling |
| Generate or fix SQL over raw tables | gen_sql |
| Explore schemas, samples, or reference context | explore |
| Build a visual report artifact | gen_visual_report |
| Create a dashboard in an external BI tool | Ask the main agent to use the installed BI plugin directly |