Skip to content

Commit 1280ff7

Browse files
authored
[Agent Builder] Add chart type specific config prompt rules to visualization tool (elastic#260269)
## Summary Resolves elastic#259508 Add support for per-chart type configuration rules that are injected into the config generation prompt. This allows chart types to define specific constrains - e.g., gauge charts should omit min/max bounds by default (included in this PR as well).
1 parent db5ee52 commit 1280ff7

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/chart_type_guidance.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 2.0.
66
*/
77

8+
import type { SupportedChartType } from '@kbn/agent-builder-common/tools/tool_result';
89
import { chartTypeRegistry } from './chart_type_registry';
910

1011
export const getChartTypeSelectionPromptContent = () =>
@@ -18,3 +19,16 @@ export const getChartTypeSelectionPromptContent = () =>
1819
...Object.entries(chartTypeRegistry).map(([, { guidance }]) => `- ${guidance.guideline}`),
1920
"- Consider the user's intent and the nature of the data being visualized",
2021
].join('\n');
22+
23+
export const getChartTypeConfigPromptContent = (chartType: SupportedChartType) => {
24+
const configPromptRules = chartTypeRegistry[chartType].configPromptRules;
25+
26+
if (!configPromptRules?.length) {
27+
return '';
28+
}
29+
30+
return [
31+
`CHART-SPECIFIC RULES FOR ${chartType.toUpperCase()}:`,
32+
...configPromptRules.map((rule) => `- ${rule}`),
33+
].join('\n');
34+
};

x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/chart_type_registry.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { mosaicStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder
2121
interface ChartTypeRegistryEntry {
2222
schema: { validate: (config: unknown) => any; getSchema: () => any };
2323
guidance: { description: string; guideline: string };
24+
configPromptRules?: string[];
2425
}
2526

2627
/**
@@ -34,7 +35,7 @@ interface ChartTypeRegistryEntry {
3435
* TypeScript enforces exhaustiveness via `satisfies Record<SupportedChartType, ...>` —
3536
* a missing entry is a compile error.
3637
*/
37-
export const chartTypeRegistry = {
38+
export const chartTypeRegistry: Record<SupportedChartType, ChartTypeRegistryEntry> = {
3839
[SupportedChartType.Metric]: {
3940
schema: esqlMetricState,
4041
guidance: {
@@ -52,6 +53,11 @@ export const chartTypeRegistry = {
5253
guideline:
5354
"Choose 'gauge' when showing a value within a range, progress toward a goal, or performance against min/max thresholds",
5455
},
56+
configPromptRules: [
57+
"Always omit the optional 'min' and 'max' fields from the final configuration.",
58+
'Do not infer, synthesize, or backfill gauge bounds from the ES|QL results or the user request.',
59+
'Only include goal/target-related fields when the user explicitly asks for a goal or threshold.',
60+
],
5561
},
5662
[SupportedChartType.XY]: {
5763
schema: xyStateSchemaESQL,
@@ -134,7 +140,7 @@ export const chartTypeRegistry = {
134140
"Choose 'mosaic' when visualizing the joint distribution of two categorical dimensions",
135141
},
136142
},
137-
} satisfies Record<SupportedChartType, ChartTypeRegistryEntry>;
143+
};
138144

139145
export type ChartTypeRegistry = typeof chartTypeRegistry;
140146

x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/prompts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import type { BaseMessageLike } from '@langchain/core/messages';
99
import type { SupportedChartType } from '@kbn/agent-builder-common/tools/tool_result';
10+
import { getChartTypeConfigPromptContent } from './chart_type_guidance';
1011

1112
export const createGenerateConfigPrompt = ({
1213
nlQuery,
@@ -25,6 +26,8 @@ export const createGenerateConfigPrompt = ({
2526
additionalChartConfigInstructions?: string;
2627
additionalContext?: string;
2728
}): BaseMessageLike[] => {
29+
const chartTypeConfigPromptContent = getChartTypeConfigPromptContent(chartType);
30+
2831
return [
2932
[
3033
'system',
@@ -65,6 +68,8 @@ NUMBER FORMAT RULES:
6568
- When column names or the user query hint at a unit (e.g. "cpu", "percent", "bytes_in", "disk_used", "latency_ms"), infer the correct format even if the user did not explicitly ask for it.
6669
- Do NOT apply a format when the metric is a plain count, rate, or when the unit is ambiguous.
6770
71+
${chartTypeConfigPromptContent ? `${chartTypeConfigPromptContent}` : ''}
72+
6873
${additionalChartConfigInstructions ?? ''}
6974
7075
Your task is to generate a ${chartType} visualization configuration based on the following information:

x-pack/platform/plugins/shared/dashboard_agent/server/skills/grid_layout_prompt.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ Every \`add_panels_from_attachments\` item requires \`grid: { x, y, w, h }\`. Th
1515
1616
Use these sizes — **do not make metric or gauge panels full-width**:
1717
18-
- **Metric / Gauge** → \`w: 8–16, h: 5–6\`. These are single-number panels — keep them **small**. Fit 3–6 per row.
18+
- **Metric** → \`w: 8–16, h: 5–6\`. These are single-number panels — keep them **small**. Fit 3–6 per row.
1919
- 6 metrics in a row: each \`w: 8, h: 5\`
2020
- 4 metrics in a row: each \`w: 12, h: 5\`
2121
- 3 metrics in a row: each \`w: 16, h: 6\`
22+
- **Gauge** → \`w: 12–16, h: 9–12\`. Gauges need extra vertical space for the dial, but should still stay compact. Fit 3–4 per row.
23+
- 4 gauges in a row: each \`w: 12, h: 9\`
24+
- 3 gauges in a row: each \`w: 16, h: 10–12\`
2225
- **XY (line / area / bar)** → \`w: 24, h: 10–12\` (half-width) or \`w: 48, h: 14–16\` (full-width for primary time series).
2326
- **Heatmap** → \`w: 24–48, h: 10–12\`. Needs height for the color matrix.
2427
- **Tagcloud** → \`w: 24, h: 8–10\`.

0 commit comments

Comments
 (0)