Skip to content

feat(service-ai): visualize_data tool — return charts from AI data queries#1820

Merged
xuyushun441-sys merged 1 commit into
mainfrom
feat/ai-visualize-data-chart
Jun 13, 2026
Merged

feat(service-ai): visualize_data tool — return charts from AI data queries#1820
xuyushun441-sys merged 1 commit into
mainfrom
feat/ai-visualize-data-chart

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

What

Lets the AI data-query assistant answer with a chart instead of only text. Adds a visualize_data tool that aggregates a data object via the existing analytics service and streams the result to the client as a data-chart part for inline rendering.

The frontend half (rendering the data-chart part in the chat bubble) is a companion PR in objectui (plugin-chatbot).

How

  • tools/visualize-data.tool.tsVISUALIZE_DATA_TOOL + handler + registerVisualizeDataTool. Maps the tool args (objectName, dimension, measures[{function,field}], chartType, where) into an AnalyticsQuery (auto-inferred cube; function+field → measure key count/<field>_sum/…), runs IAnalyticsService.query, shapes rows into the SDUI <chart> contract (chartType, data, xAxisKey, series), and emits ctx.onProgress({ type: 'data-chart', id, data }). Returns a compact JSON summary so the model narrates.
  • plugin.ts — registers the tool when an analytics service is present; persists it as tool metadata in lockstep (Studio visibility).
  • skills/data-explorer-skill.ts — exposes visualize_data, adds chart trigger phrases, and instructs the agent to prefer it for "chart/plot/trend/breakdown" asks.

Reuses the same onProgress → Vercel UI-message-stream data-* channel that data-build-progress already uses — no protocol/contract changes.

Testing

  • Unit: visualize-data.tool.test.ts (5 tests) — measure-key mapping, where pass-through, default chartType, data-chart payload shape, error path.
  • End-to-end (live, real LLM via Vercel AI Gateway): AI picks visualize_data → analytics auto-infers a cube for showcase_task by statusdata-chart part → a 5-bar chart renders in the console chat bubble.

🤖 Generated with Claude Code

…eries

Adds a `visualize_data` AI tool so the data-query assistant can answer with
a CHART instead of plain text/markdown. The tool runs an aggregation through
the existing analytics service (auto-inferred cube), maps the result into the
SDUI `<chart>` contract, and emits it to the client as a `data-chart` custom
stream part (same onProgress → Vercel UI-message-stream channel that
`data-build-progress` already uses). It also returns a compact textual summary
so the model narrates the answer alongside the rendered chart.

- tools/visualize-data.tool.ts: VISUALIZE_DATA_TOOL + handler + register fn.
  function+field → analytics measure key (count / <field>_sum / …); single
  dimension → x-axis; measures → series; chartType (bar/line/pie/…).
- plugin.ts: register when an analytics service is present; persist as tool
  metadata in lockstep (Studio visibility).
- skills/data-explorer-skill.ts: expose visualize_data + chart trigger phrases
  and guidance to prefer it for "chart/plot/trend/breakdown" requests.

Frontend rendering lands in objectui (plugin-chatbot). Verified end-to-end in
the console against a live LLM: AI picks visualize_data → analytics aggregates
→ data-chart part → bar chart renders in the chat bubble.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 13, 2026 8:56pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants