Repository navigation
Description
What
Give the in-product agent the ability to render charts inline in its replies. Today the agent can quote numbers from get_visibility_trend, get_competitor_comparison, etc. as a list — but the moment a question is "how is X changing over time" or "compare Y across N brands", a chart conveys it in one glance where a table or prose takes a paragraph.
Modern agent UIs (ChatGPT, Claude.ai, Perplexity) all do this. We can match the affordance with our existing stack.
Why
- The data tools the agent already calls return naturally chart-shaped payloads (time series, grouped counts, per-source breakdowns). They're currently rendered as text only — the visual half of the answer is missing.
- The dashboard already uses Recharts for
/dashboard/insights,/dashboard/competitors, etc. Reusing it inside agent bubbles keeps theme / responsive behavior consistent and adds no new dependency. - Native React rendering beats the "Python interpreter → PNG" pattern (ChatGPT) for our case: zero extra infra, theme-aware, persists for free (tool output is already saved as part of
agent_messages.tool_callsJSONB, so reload re-renders the chart without re-running the agent).
Proposed approach
A new tool — render_chart — that the agent calls after it has the data it wants to visualize. The tool is intentionally inert: it just validates and echoes its input back. The frontend recognizes the tool-render_chart part type and renders a Recharts component from the input.
Example agent turn:
User: "son 30 günde brand mention trendi nasıl?"
Agent step 1 (get_visibility_trend):
→ [{ date: '2026-04-30', mentions: 12, citations: 4 }, …]
Agent step 2 (render_chart):
→ {
type: 'line',
title: 'Visibility trend — last 30 days',
data: <output of step 1>,
xKey: 'date',
series: [
{ key: 'mentions', label: 'Mentions' },
{ key: 'citations', label: 'Citations' },
],
}
Agent text: "Mentions went 12 → 28, citations 4 → 11. The jump on May 3rd
correlates with the new ChatGPT prompt set going live."
Scope
- Tool: add
render_charttoweb/src/lib/agent/tools.ts. Input schema acceptstype('line' | 'bar' | 'pie'),title?,data(array, max 200 items),xKey(for line/bar),series(array of{ key, label, color? }), orvalueKey+labelKey(pie).executereturns the input verbatim (UI does the rendering). - Component: new
web/src/components/agent/agent-chart.tsx— a Recharts wrapper that maps the spec to<LineChart>/<BarChart>/<PieChart>. Uses the same--chart-*CSS variables the dashboard charts use, so dark/light mode just works. - Disclosure dispatch: extend
ToolCallDisclosureso therender_charttool part renders the chart inline (in place of the collapsed JSON disclosure). Other tools keep the existing chip+JSON UI. - System prompt: add a paragraph in
web/src/lib/agent/system-prompt.ts— when the question is about trends / comparisons / breakdowns, callrender_chartafter the data tool and pass the values verbatim; never invent numbers, never reformat the series. Two-three examples ("for time series use type=line, xKey=date", etc.).
Acceptance criteria
- Agent renders a line chart for "how did X change over time" questions, a bar chart for "compare across competitors" questions, and a pie for "where do my citations come from" questions
- Chart spec persists with the message — reload the conversation and the chart re-renders without re-running tool calls
- Charts honor dark / light theme automatically
- Data point cap (200) enforced in the tool's input schema; oversized input returns a clear validation error the agent can recover from
-
pnpm tsc --noEmit+pnpm format:checkclean
Out of scope
- Multi-axis / dual-scale charts. Single value axis only in v1.
- Drilldown / interactivity beyond Recharts' built-in tooltip.
- A "show as table" toggle. Pure render-as-described for the MVP.
- Sankey, heatmap, geo, or any chart type not already used elsewhere in the dashboard.
- Citing where the chart's data came from. The agent's accompanying text should reference the source; we don't enforce a
sourceToolCallIdfield yet (deferred until we see whether the system-prompt rule is enough).
Activity
feat(agent): render_chart tool + inline Recharts visualizations (#138)