@axiom-lattice/examples-deep_research 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +4 -4
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +11 -0
- package/dist/index.js +40 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/agents/data_agent/skills/business-analytics/README.md +121 -0
- package/src/agents/data_agent/skills/business-analytics/SKILL.md +187 -108
- package/src/agents/data_agent/skills/business-analytics/examples.md +295 -0
- package/src/agents/data_agent/skills/business-analytics/reference.md +240 -0
- package/src/agents/data_agent/skills/business-analytics/resources/data/sample.json +66 -0
- package/src/agents/data_agent/skills/business-analytics/resources/prompts/analyze.txt +128 -0
- package/src/agents/data_agent/skills/business-analytics/resources/templates/report-template.md +260 -0
- package/src/agents/data_agent/skills/chart-markdown/SKILL.md +91 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/README.md +16 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/data-patterns.md +14 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/finance.md +7 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/formatting.md +14 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/hr-people.md +7 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/marketing-growth.md +7 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/operations-supply-chain.md +7 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/sales-retail.md +8 -0
- package/src/agents/data_agent/skills/chart-markdown/resources/examples.md +80 -0
- package/src/agents/data_agent/skills/metrics-query/SKILL.md +296 -0
- package/src/index-with-auth.ts +122 -0
- package/src/index.ts +55 -1
- package/src/agents/data_agent/skills/generate-chart-md/SKILL.md +0 -176
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: chart-markdown
|
|
3
|
+
description: Selects an appropriate chart type (bar, line, pie, scatter, heatmap, funnel, gauge, radar) from data analysis or query results and generates a chart markdown block containing JSON for external chart libraries. Use when the user asks to visualize query results, analysis data, or to create bar charts, line charts, pie charts, scatter plots, or other chart types from tabular or aggregated data.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Chart Markdown Block
|
|
7
|
+
|
|
8
|
+
## Chart type selection
|
|
9
|
+
|
|
10
|
+
Choose by data shape and question:
|
|
11
|
+
|
|
12
|
+
- **Bar** (bar): Compare categories or time periods. Use category xAxis, value yAxis. Multiple series for grouped or stacked bars.
|
|
13
|
+
- **Line** (line): Show trends over time. Use category or time xAxis, value yAxis. Multiple series for multiple metrics.
|
|
14
|
+
- **Pie** (pie): Show composition or share. No axes. Data: `[{value: number, name: string}, ...]`. Use `radius: ["40%", "70%"]` for donut.
|
|
15
|
+
- **Scatter** (scatter): Correlation or distribution. Use value xAxis and value yAxis. Data: `[[x, y], [x, y], ...]`.
|
|
16
|
+
- **Heatmap** (heatmap): Two dimensions + value. Category xAxis and yAxis. Data: `[[xIndex, yIndex, value], ...]`.
|
|
17
|
+
- **Funnel** (funnel): Sequential stages or conversion. Data: `[{value, name}, ...]`. Use `sort: "ascending"` or `"descending"`.
|
|
18
|
+
- **Gauge** (gauge): Single KPI or progress. One series with `data: [{value, name}]`.
|
|
19
|
+
- **Radar** (radar): Multi-dimensional comparison. Define `radar.indicator` and series with `value` arrays.
|
|
20
|
+
|
|
21
|
+
## Output format
|
|
22
|
+
|
|
23
|
+
Emit a single fenced code block with language **chart**. Body is one JSON object:
|
|
24
|
+
|
|
25
|
+
- **table**: Array of rows (original or summary data) for reference.
|
|
26
|
+
- **echarts**: ECharts option object (title, tooltip, legend, xAxis, yAxis, series, etc.).
|
|
27
|
+
|
|
28
|
+
```chart
|
|
29
|
+
{
|
|
30
|
+
"table": [["Category", "Value"], ["A", 10], ["B", 20]],
|
|
31
|
+
"echarts": { ... }
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Schema requirements
|
|
36
|
+
|
|
37
|
+
- **title**: `{"text": "Clear chart title"}`.
|
|
38
|
+
- **tooltip**: Use `trigger: "axis"` for bar/line; `trigger: "item"` for pie/scatter/funnel.
|
|
39
|
+
- **xAxis / yAxis**: Omit for pie/funnel/gauge. Use `type: "category"` or `"time"` or `"value"`; provide `data` when type is category.
|
|
40
|
+
- **series**: One or more items. Each has `type`, `name`, `data`. Pie data: `[{value, name}]`. Scatter data: `[[x,y], ...]`. Bar/line: array of values or category-mapped values.
|
|
41
|
+
- **legend**: Include when there are multiple series.
|
|
42
|
+
|
|
43
|
+
## Best practices
|
|
44
|
+
|
|
45
|
+
- Use clear, business-facing titles and axis labels (not raw field names).
|
|
46
|
+
- Format numbers (percent, currency, thousands) in tooltip and axis labels.
|
|
47
|
+
- For time series, use `xAxis.type: "time"` and consistent date format.
|
|
48
|
+
- Show important values on the chart with `series.label` when useful.
|
|
49
|
+
- For industry- or data-type-specific guidance, see [best-practices/README.md](best-practices/README.md) (data patterns, formatting, and one file per industry: sales-retail, finance, marketing-growth, operations-supply-chain, hr-people).
|
|
50
|
+
|
|
51
|
+
## Examples
|
|
52
|
+
|
|
53
|
+
### Bar chart (category comparison)
|
|
54
|
+
|
|
55
|
+
```chart
|
|
56
|
+
{
|
|
57
|
+
"table": [["Product", "Sales"], ["Product A", 320], ["Product B", 280], ["Product C", 250]],
|
|
58
|
+
"echarts": {
|
|
59
|
+
"title": {"text": "Top products by sales"},
|
|
60
|
+
"tooltip": {"trigger": "axis"},
|
|
61
|
+
"xAxis": {"type": "category", "data": ["Product A", "Product B", "Product C"], "name": "Product"},
|
|
62
|
+
"yAxis": {"type": "value", "name": "Sales"},
|
|
63
|
+
"series": [{"type": "bar", "data": [320, 280, 250], "label": {"show": true, "position": "top"}}]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Pie chart (composition)
|
|
69
|
+
|
|
70
|
+
```chart
|
|
71
|
+
{
|
|
72
|
+
"table": [["Channel", "Count"], ["Online", 450], ["Offline", 320], ["Partner", 180]],
|
|
73
|
+
"echarts": {
|
|
74
|
+
"title": {"text": "Customer acquisition by channel"},
|
|
75
|
+
"tooltip": {"trigger": "item", "formatter": "{b}: {c} ({d}%)"},
|
|
76
|
+
"legend": {"orient": "vertical", "right": "10%", "top": "center"},
|
|
77
|
+
"series": [{
|
|
78
|
+
"type": "pie",
|
|
79
|
+
"radius": ["40%", "70%"],
|
|
80
|
+
"data": [
|
|
81
|
+
{"value": 450, "name": "Online"},
|
|
82
|
+
{"value": 320, "name": "Offline"},
|
|
83
|
+
{"value": 180, "name": "Partner"}
|
|
84
|
+
],
|
|
85
|
+
"label": {"formatter": "{b}\n{d}%"}
|
|
86
|
+
}]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For more chart types (line, scatter, funnel, gauge, radar), see [examples.md](examples.md).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Chart best practices by context
|
|
2
|
+
|
|
3
|
+
Use when the analysis context is clear to pick the right chart and conventions.
|
|
4
|
+
|
|
5
|
+
## General
|
|
6
|
+
|
|
7
|
+
- [Data patterns](data-patterns.md) — Chart choice by question type (trend, comparison, share, correlation, etc.)
|
|
8
|
+
- [Formatting](formatting.md) — Currency, percent, time, counts; "when in doubt" rules
|
|
9
|
+
|
|
10
|
+
## By industry
|
|
11
|
+
|
|
12
|
+
- [Sales & retail](sales-retail.md)
|
|
13
|
+
- [Finance & accounting](finance.md)
|
|
14
|
+
- [Marketing & growth](marketing-growth.md)
|
|
15
|
+
- [Operations & supply chain](operations-supply-chain.md)
|
|
16
|
+
- [HR & people](hr-people.md)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Chart choice by data pattern
|
|
2
|
+
|
|
3
|
+
Use when the analysis question is clear but industry is generic. Pick chart by pattern:
|
|
4
|
+
|
|
5
|
+
| Pattern | Typical question | Preferred chart | Notes |
|
|
6
|
+
|--------|-------------------|-----------------|--------|
|
|
7
|
+
| **Trend over time** | How did X change over time? | Line | Use `xAxis.type: "time"` for continuous dates; category for discrete periods (month, quarter). |
|
|
8
|
+
| **Category comparison** | Which category is largest? Rank? | Bar | Horizontal bar if many categories or long labels. |
|
|
9
|
+
| **Part-to-whole** | What is the share of each part? | Pie / donut | Limit to 5–7 segments; combine small slices into "Other" if needed. |
|
|
10
|
+
| **Correlation / distribution** | How do two measures relate? | Scatter | Optional: size or color for a third dimension. |
|
|
11
|
+
| **Conversion / funnel** | How many pass each stage? | Funnel | Sort by stage order; show count and % in tooltip. |
|
|
12
|
+
| **Single KPI vs target** | Are we on track? | Gauge | One value; clear min/max or target bands. |
|
|
13
|
+
| **Two dimensions + value** | How does value vary by two categories? | Heatmap | Use for matrices (e.g. region × product, hour × day). |
|
|
14
|
+
| **Multi-dimensional profile** | How do entities compare on several metrics? | Radar | Same scale per dimension; 2–3 series max. |
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Finance & accounting
|
|
2
|
+
|
|
3
|
+
- **P&L / cash flow over time**: Line or stacked bar; use consistent currency and scale.
|
|
4
|
+
- **Expense or revenue breakdown**: Pie or horizontal bar; format as currency.
|
|
5
|
+
- **Variance (actual vs budget)**: Bar with two series (actual, budget) or bar with variance %.
|
|
6
|
+
- **Portfolio or segment weight**: Pie; keep segments readable (aggregate small ones).
|
|
7
|
+
- **Key ratios (e.g. current ratio)**: Gauge or single big number; show benchmark if relevant.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Formatting conventions
|
|
2
|
+
|
|
3
|
+
- **Currency**: Use locale format (e.g. 1,234.56 or 1 234,56); indicate unit in axis title (e.g. "Revenue (CNY)").
|
|
4
|
+
- **Percent**: Show as "X%" in labels/tooltip; ensure sum = 100% for pie if showing share.
|
|
5
|
+
- **Time**: Same granularity and format across the chart (e.g. "Jan 2024" or "2024-Q1"); use `xAxis.type: "time"` for continuous.
|
|
6
|
+
- **Counts**: Prefer integers in labels; use K/M suffix for large numbers (e.g. "1.2M") if needed.
|
|
7
|
+
- **Ranking**: Sort by value (descending unless natural order e.g. funnel); limit to top N (e.g. 10) for clarity.
|
|
8
|
+
|
|
9
|
+
## When in doubt
|
|
10
|
+
|
|
11
|
+
1. Match the chart to the **primary question** (trend → line, compare → bar, share → pie, relation → scatter).
|
|
12
|
+
2. Prefer **fewer series and categories**; aggregate or "Other" instead of cluttering.
|
|
13
|
+
3. Use **consistent terminology** with the domain (e.g. "Revenue" vs "Sales" as in the data source).
|
|
14
|
+
4. Add a **short, descriptive title** and axis/label names that a business user would recognize.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# HR & people
|
|
2
|
+
|
|
3
|
+
- **Headcount or turnover over time**: Line; stacked area for composition (e.g. by department).
|
|
4
|
+
- **Department or role mix**: Pie or horizontal bar.
|
|
5
|
+
- **Performance vs potential (9-box style)**: Scatter; optional quadrants.
|
|
6
|
+
- **Survey or engagement scores**: Bar (by dimension or question); show scale (e.g. 1–5).
|
|
7
|
+
- **Diversity or composition**: Pie or stacked bar; consistent categories.
|
package/src/agents/data_agent/skills/chart-markdown/resources/best-practices/marketing-growth.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Marketing & growth
|
|
2
|
+
|
|
3
|
+
- **Traffic or conversions over time**: Line; multiple series for channels or segments.
|
|
4
|
+
- **Channel attribution / mix**: Pie or stacked bar.
|
|
5
|
+
- **Funnel (visit → signup → pay)**: Funnel; show drop-off and conversion %.
|
|
6
|
+
- **Cohort or retention matrix**: Heatmap (e.g. month × retention week).
|
|
7
|
+
- **Campaign comparison**: Bar (by campaign) or radar (multi-metric).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Operations & supply chain
|
|
2
|
+
|
|
3
|
+
- **Throughput or utilization over time**: Line or bar; add target line if relevant.
|
|
4
|
+
- **Inventory or capacity by location/SKU**: Bar (ranking) or heatmap (location × SKU).
|
|
5
|
+
- **Lead time or cycle time distribution**: Bar (buckets) or line (over time).
|
|
6
|
+
- **Quality / defect rate**: Line over time; gauge for single KPI vs target.
|
|
7
|
+
- **Supplier or lane performance**: Bar or radar (cost, quality, delivery).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Sales & retail
|
|
2
|
+
|
|
3
|
+
- **Revenue / volume over time**: Line; group by region or product with multiple series and legend.
|
|
4
|
+
- **Product or SKU ranking**: Bar (vertical for top N); show value labels on bars.
|
|
5
|
+
- **Channel or segment mix**: Pie or donut; label with share (%) and optionally count.
|
|
6
|
+
- **Sales vs margin / discount**: Scatter (e.g. volume vs margin); size by revenue if needed.
|
|
7
|
+
- **Pipeline or stage conversion**: Funnel; sort descending (top = first stage).
|
|
8
|
+
- **Target attainment**: Gauge (e.g. quota %) or bar (actual vs target by period).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Chart markdown examples
|
|
2
|
+
|
|
3
|
+
Additional examples for line, scatter, funnel, and gauge. Replace sample data with real query or analysis results.
|
|
4
|
+
|
|
5
|
+
## Line chart (time trend)
|
|
6
|
+
|
|
7
|
+
```chart
|
|
8
|
+
{
|
|
9
|
+
"table": [["Month", "Revenue"], ["Jan", 120000], ["Feb", 135000], ["Mar", 142000]],
|
|
10
|
+
"echarts": {
|
|
11
|
+
"title": {"text": "Quarterly revenue trend"},
|
|
12
|
+
"tooltip": {"trigger": "axis"},
|
|
13
|
+
"legend": {"data": ["Revenue"]},
|
|
14
|
+
"xAxis": {"type": "category", "data": ["Jan", "Feb", "Mar"], "name": "Month"},
|
|
15
|
+
"yAxis": {"type": "value", "name": "Revenue"},
|
|
16
|
+
"series": [{"name": "Revenue", "type": "line", "data": [120000, 135000, 142000], "smooth": true}]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Scatter chart (correlation)
|
|
22
|
+
|
|
23
|
+
```chart
|
|
24
|
+
{
|
|
25
|
+
"table": [["Sales", "Profit"], [120, 35], [150, 42], [200, 55], [250, 68]],
|
|
26
|
+
"echarts": {
|
|
27
|
+
"title": {"text": "Sales vs profit"},
|
|
28
|
+
"tooltip": {"trigger": "item", "formatter": "Sales: {c0}<br/>Profit: {c1}"},
|
|
29
|
+
"xAxis": {"type": "value", "name": "Sales"},
|
|
30
|
+
"yAxis": {"type": "value", "name": "Profit"},
|
|
31
|
+
"series": [{"type": "scatter", "symbolSize": 12, "data": [[120, 35], [150, 42], [200, 55], [250, 68]]}]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Funnel chart (conversion stages)
|
|
37
|
+
|
|
38
|
+
```chart
|
|
39
|
+
{
|
|
40
|
+
"table": [["Stage", "Count"], ["Visit", 5000], ["Register", 2000], ["Activate", 1500], ["Pay", 600]],
|
|
41
|
+
"echarts": {
|
|
42
|
+
"title": {"text": "Conversion funnel"},
|
|
43
|
+
"tooltip": {"trigger": "item", "formatter": "{b}: {c} ({d}%)"},
|
|
44
|
+
"series": [{
|
|
45
|
+
"type": "funnel",
|
|
46
|
+
"left": "10%",
|
|
47
|
+
"width": "80%",
|
|
48
|
+
"sort": "descending",
|
|
49
|
+
"gap": 4,
|
|
50
|
+
"label": {"show": true, "position": "inside", "formatter": "{b}\n{c}"},
|
|
51
|
+
"data": [
|
|
52
|
+
{"value": 5000, "name": "Visit"},
|
|
53
|
+
{"value": 2000, "name": "Register"},
|
|
54
|
+
{"value": 1500, "name": "Activate"},
|
|
55
|
+
{"value": 600, "name": "Pay"}
|
|
56
|
+
]
|
|
57
|
+
}]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Gauge (single KPI)
|
|
63
|
+
|
|
64
|
+
```chart
|
|
65
|
+
{
|
|
66
|
+
"table": [["Metric", "Value", "Target"], ["Sales", 850, 1000]],
|
|
67
|
+
"echarts": {
|
|
68
|
+
"title": {"text": "Sales target completion"},
|
|
69
|
+
"series": [{
|
|
70
|
+
"type": "gauge",
|
|
71
|
+
"center": ["50%", "60%"],
|
|
72
|
+
"radius": "90%",
|
|
73
|
+
"axisLine": {"lineStyle": [{"color": [[0.3, "#91c7ae"], [0.7, "#63869e"], [1, "#c23531"]]}]},
|
|
74
|
+
"pointer": {"itemStyle": {"color": "auto"}},
|
|
75
|
+
"detail": {"formatter": "{value}%", "fontSize": 24, "offsetCenter": [0, "70%"]},
|
|
76
|
+
"data": [{"value": 85, "name": "Completion"}]
|
|
77
|
+
}]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: metrics-query
|
|
3
|
+
description: Query business metrics using the three-step workflow. Discover available metrics, understand metric definitions, and execute queries with proper filters and groupings.
|
|
4
|
+
metadata:
|
|
5
|
+
category: data_analysis
|
|
6
|
+
tools:
|
|
7
|
+
- query_metrics_list
|
|
8
|
+
- query_metric_definition
|
|
9
|
+
- query_semantic_metric_data
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Overview: The Three-Step Loop
|
|
13
|
+
|
|
14
|
+
1. **query_metrics_list** → Discover what metrics exist
|
|
15
|
+
2. **query_metric_definition** → Understand one metric before querying it
|
|
16
|
+
3. **query_semantic_metric_data** → Execute the query with the right parameters
|
|
17
|
+
|
|
18
|
+
Repeat steps 2-3 for each metric the user asks about. Drill-down means running step 3 multiple times with progressively narrower filters.
|
|
19
|
+
|
|
20
|
+
## Step 1 — Discover Available Metrics
|
|
21
|
+
|
|
22
|
+
**Tool**: `query_metrics_list`
|
|
23
|
+
|
|
24
|
+
**Parameters**:
|
|
25
|
+
- `serverKey` (required): Target semantic metrics server
|
|
26
|
+
- `datasourceIds` (optional): Array of datasource IDs to query. If not provided, uses all selected datasources.
|
|
27
|
+
|
|
28
|
+
**Response Fields**:
|
|
29
|
+
| Field | Description | Usage |
|
|
30
|
+
|-------|-------------|-------|
|
|
31
|
+
| metricName | Metric identifier | Pass to query_metric_definition and query_semantic_metric_data |
|
|
32
|
+
| domain | Metric category | Groups related metrics (e.g., sales_performance, pricing_and_margin) |
|
|
33
|
+
| shortDesc | One-line description | Present to user |
|
|
34
|
+
| displayName | Human-readable name | Display in results |
|
|
35
|
+
|
|
36
|
+
**When to Use**:
|
|
37
|
+
- User asks about metrics without specifying exact names
|
|
38
|
+
- Starting any metrics-related conversation
|
|
39
|
+
- Finding metrics by domain or keywords
|
|
40
|
+
|
|
41
|
+
**Next Step**: After finding relevant metrics, call `query_metric_definition` with the `metricName`.
|
|
42
|
+
|
|
43
|
+
## Step 2 — Read the Metric Definition
|
|
44
|
+
|
|
45
|
+
**Tool**: `query_metric_definition`
|
|
46
|
+
|
|
47
|
+
**Parameters**:
|
|
48
|
+
- `serverKey` (required): Target semantic metrics server
|
|
49
|
+
- `metricName` (required): The name of the metric to get definition for
|
|
50
|
+
- `datasourceId` (optional): Specific datasource ID to search in. If not provided, searches all selected datasources.
|
|
51
|
+
|
|
52
|
+
This response is self-contained. Everything you need to write a correct query is here.
|
|
53
|
+
|
|
54
|
+
### 2.1 Identify the Time Axis (defaultTimeContext)
|
|
55
|
+
|
|
56
|
+
The `defaultTimeContext` tells you the primary date field and exactly how to use it:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"timeDimension": "DocDate",
|
|
61
|
+
"label": "单据日期",
|
|
62
|
+
"granularity": "month",
|
|
63
|
+
"window": "current_month",
|
|
64
|
+
"supportedGrains": ["day", "week", "month", "year"]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Rules**:
|
|
69
|
+
- To filter by date: Copy the pattern and replace values
|
|
70
|
+
```json
|
|
71
|
+
{"dimension": "DocDate", "operator": "BETWEEN", "values": ["2025-01-01", "2025-12-31"]}
|
|
72
|
+
```
|
|
73
|
+
- To group by time: Use `"{timeDimension}__{grain}"` format (e.g., `"DocDate__month"`)
|
|
74
|
+
|
|
75
|
+
### 2.2 Identify Available Dimensions (supportedDimensions)
|
|
76
|
+
|
|
77
|
+
`supportedDimensions` lists every axis available for GROUP BY and filtering. Each entry has:
|
|
78
|
+
- `dim_id`: Use this (NOT `field_name`) in filters and groupBy
|
|
79
|
+
- `field_name`: Human-readable field name
|
|
80
|
+
- `type`: `"categorical"` (strings) or `"datetime"` (dates)
|
|
81
|
+
|
|
82
|
+
**Categorical Dimensions**:
|
|
83
|
+
- Values are strings
|
|
84
|
+
- Use `IN` for multiple values, `EQ` / `NEQ` for single
|
|
85
|
+
- Example: `{"dimension": "org_region", "operator": "IN", "values": ["华东", "华南"]}`
|
|
86
|
+
|
|
87
|
+
**Datetime Dimensions**:
|
|
88
|
+
- Values are YYYY-MM-DD format
|
|
89
|
+
- Use `BETWEEN` for ranges, `GT` / `LT` for open-ended
|
|
90
|
+
- Group format: `"{dim_id}__{grain}"` where grain is lowercase: `day`, `week`, `month`, `year`
|
|
91
|
+
- Example groupBy: `["DocDate__month"]`
|
|
92
|
+
|
|
93
|
+
### 2.3 Understand Result Polarity (aiAgentContext.polarity)
|
|
94
|
+
|
|
95
|
+
- `"positive"` — Higher value is better (e.g., order amount, delivery qty)
|
|
96
|
+
- `"negative"` — Lower value is better (e.g., discount rate, return amount)
|
|
97
|
+
|
|
98
|
+
Use this when summarizing results to the user (e.g., "the discount rate increased, which is a negative sign").
|
|
99
|
+
|
|
100
|
+
**Next Step**: Call `query_semantic_metric_data` with parameters derived from this definition.
|
|
101
|
+
|
|
102
|
+
## Step 3 — Execute a Query
|
|
103
|
+
|
|
104
|
+
**Tool**: `query_semantic_metric_data`
|
|
105
|
+
|
|
106
|
+
**Parameters**:
|
|
107
|
+
- `serverKey` (required): Target semantic metrics server
|
|
108
|
+
- `datasourceId` (required): The data source ID to query metrics from
|
|
109
|
+
- `metrics` (required): Array of metric names to query (e.g., `["net_sales_amt", "gross_profit"]`)
|
|
110
|
+
- `groupBy` (optional): Array of dimensions to group by (e.g., `["DocDate__month", "org_region"]`)
|
|
111
|
+
- `filters` (optional): Array of filters to apply
|
|
112
|
+
- `orderBy` (optional): Array of sort specifications
|
|
113
|
+
- `limit` (optional): Maximum number of results (default: 1000)
|
|
114
|
+
- `debug` (optional): Set to `true` to receive executed SQL for verification
|
|
115
|
+
|
|
116
|
+
**Full Request Schema**:
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"serverKey": "your_server",
|
|
120
|
+
"datasourceId": "1",
|
|
121
|
+
"metrics": ["metric_name"],
|
|
122
|
+
"groupBy": ["dim_id or DocDate__grain"],
|
|
123
|
+
"filters": [{"dimension": "dim_id", "operator": "OP", "values": ["..."]}],
|
|
124
|
+
"orderBy": [{"field": "field_name", "direction": "ASC|DESC"}],
|
|
125
|
+
"limit": 100,
|
|
126
|
+
"debug": false
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Filter Operator Reference
|
|
131
|
+
|
|
132
|
+
| Operator | Applies To | Values Array |
|
|
133
|
+
|----------|------------|--------------|
|
|
134
|
+
| BETWEEN | datetime, number | [min, max] (inclusive) |
|
|
135
|
+
| IN | categorical | ["v1", "v2", ...] |
|
|
136
|
+
| EQ | any | ["v"] |
|
|
137
|
+
| NEQ | any | ["v"] |
|
|
138
|
+
| GT / GTE | datetime, number | ["v"] |
|
|
139
|
+
| LT / LTE | datetime, number | ["v"] |
|
|
140
|
+
| LIKE | string | ["%pattern%"] |
|
|
141
|
+
| NOT_NULL | any | [] |
|
|
142
|
+
|
|
143
|
+
## Workflow Patterns
|
|
144
|
+
|
|
145
|
+
### Pattern A — Time Trend (most common first query)
|
|
146
|
+
|
|
147
|
+
**Goal**: Show how a metric changes over time within a period.
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"serverKey": "your_server",
|
|
152
|
+
"datasourceId": "1",
|
|
153
|
+
"metrics": ["order_amt_tax_inc"],
|
|
154
|
+
"groupBy": ["DocDate__month"],
|
|
155
|
+
"filters": [{"dimension": "DocDate", "operator": "BETWEEN", "values": ["2025-01-01", "2025-12-31"]}],
|
|
156
|
+
"orderBy": [{"field": "DocDate__month", "direction": "ASC"}]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Use `DocDate__week` or `DocDate__day` for shorter time windows.
|
|
161
|
+
|
|
162
|
+
### Pattern B — Dimension Breakdown (who/what is top or bottom)
|
|
163
|
+
|
|
164
|
+
**Goal**: Rank performance across a categorical dimension in a fixed period.
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"serverKey": "your_server",
|
|
169
|
+
"datasourceId": "1",
|
|
170
|
+
"metrics": ["order_amt_tax_inc"],
|
|
171
|
+
"groupBy": ["org_region"],
|
|
172
|
+
"filters": [{"dimension": "DocDate", "operator": "BETWEEN", "values": ["2025-01-01", "2025-03-31"]}],
|
|
173
|
+
"orderBy": [{"field": "value", "direction": "DESC"}],
|
|
174
|
+
"limit": 10
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Pick `dim_id` values from `supportedDimensions` in the detail response.
|
|
179
|
+
|
|
180
|
+
### Pattern C — Drill Down (zoom into an anomaly)
|
|
181
|
+
|
|
182
|
+
**Goal**: After Pattern A reveals a bad month, find which segment caused it.
|
|
183
|
+
|
|
184
|
+
**Step 1**: Find the anomaly month using Pattern A
|
|
185
|
+
|
|
186
|
+
**Step 2**: Drill into that month by adding a categorical dimension:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"serverKey": "your_server",
|
|
191
|
+
"datasourceId": "1",
|
|
192
|
+
"metrics": ["order_amt_tax_inc"],
|
|
193
|
+
"groupBy": ["sales_person"],
|
|
194
|
+
"filters": [
|
|
195
|
+
{"dimension": "DocDate", "operator": "BETWEEN", "values": ["2025-06-01", "2025-06-30"]},
|
|
196
|
+
{"dimension": "org_region", "operator": "EQ", "values": ["华东"]}
|
|
197
|
+
],
|
|
198
|
+
"orderBy": [{"field": "value", "direction": "ASC"}]
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Step 3** (optional): Add a second groupBy dimension to cross-analyze:
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"groupBy": ["sales_person", "product_category"],
|
|
206
|
+
...
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Pattern D — Multi-Metric Comparison
|
|
211
|
+
|
|
212
|
+
**Goal**: Query two or more metrics in one call to compare them side-by-side.
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"serverKey": "your_server",
|
|
217
|
+
"datasourceId": "1",
|
|
218
|
+
"metrics": ["order_amt_tax_inc", "net_sales_amt"],
|
|
219
|
+
"groupBy": ["DocDate__month"],
|
|
220
|
+
"filters": [{"dimension": "DocDate", "operator": "BETWEEN", "values": ["2025-01-01", "2025-12-31"]}],
|
|
221
|
+
"orderBy": [{"field": "DocDate__month", "direction": "ASC"}]
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The response contains one `results[]` entry per metric. Each entry has its own `rows[]` and `metricName` label.
|
|
226
|
+
|
|
227
|
+
### Pattern E — Time × Dimension Cross-Analysis
|
|
228
|
+
|
|
229
|
+
**Goal**: See how a dimension behaves across time (e.g., monthly sales by region).
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"serverKey": "your_server",
|
|
234
|
+
"datasourceId": "1",
|
|
235
|
+
"metrics": ["order_amt_tax_inc"],
|
|
236
|
+
"groupBy": ["DocDate__month", "org_region"],
|
|
237
|
+
"filters": [{"dimension": "DocDate", "operator": "BETWEEN", "values": ["2025-01-01", "2025-06-30"]}],
|
|
238
|
+
"orderBy": [
|
|
239
|
+
{"field": "DocDate__month", "direction": "ASC"},
|
|
240
|
+
{"field": "org_region", "direction": "ASC"}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Recommended Analysis Flow
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
User question
|
|
249
|
+
│
|
|
250
|
+
▼
|
|
251
|
+
Step 1: query_metrics_list — find matching metric(s)
|
|
252
|
+
│
|
|
253
|
+
▼
|
|
254
|
+
Step 2: query_metric_definition — read defaultTimeContext + supportedDimensions
|
|
255
|
+
│
|
|
256
|
+
▼
|
|
257
|
+
Step 3a: Pattern A (time trend) — get the big picture
|
|
258
|
+
│
|
|
259
|
+
├─ anomaly found? ──► Step 3c: Pattern C (drill down)
|
|
260
|
+
│
|
|
261
|
+
├─ user asks "who"? ──► Step 3b: Pattern B (dimension breakdown)
|
|
262
|
+
│
|
|
263
|
+
└─ user asks "compare X and Y"? ──► Step 3d: Pattern D (multi-metric)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Always start broad (monthly trend over a year), then narrow (weekly in the problem month), then pinpoint (drill by dimension in the problem week).
|
|
267
|
+
|
|
268
|
+
## Debug Mode
|
|
269
|
+
|
|
270
|
+
Set `"debug": true` to receive `executedSqls` in the response. Use this to verify that the generated SQL matches your intent before presenting results to the user.
|
|
271
|
+
|
|
272
|
+
```json
|
|
273
|
+
{
|
|
274
|
+
...,
|
|
275
|
+
"debug": true
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Response**:
|
|
280
|
+
```json
|
|
281
|
+
{
|
|
282
|
+
"results": [...],
|
|
283
|
+
"executedSqls": ["SELECT TO_NVARCHAR(\"DocDate\", 'YYYY-MM') AS \"DocDate__month\", SUM(\"GTotal\") AS \"value\" FROM MTC_VW_AI_ORDR WHERE ..."]
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Common Mistakes to Avoid
|
|
288
|
+
|
|
289
|
+
| Mistake | Correct Approach |
|
|
290
|
+
|---------|------------------|
|
|
291
|
+
| Using `field_name` (e.g., `"SlpName"`) in groupBy | Use `dim_id` (e.g., `"sales_person"`) |
|
|
292
|
+
| Writing `"DocDate__Month"` (capital M) | Always lowercase grain: `"DocDate__month"` |
|
|
293
|
+
| Omitting a date filter entirely | ALWAYS include at least one DocDate filter to avoid full-table scans |
|
|
294
|
+
| Querying a metric by an unsupported dimension | Only use `dim_id` values listed in the detail response |
|
|
295
|
+
| Putting a groupBy field in orderBy using its display name | `orderBy.field` must match exactly what's in `groupBy` |
|
|
296
|
+
| Using wrong operator for dimension type | categorical → IN/EQ, datetime → BETWEEN/GT/LT |
|