Skip to content

Agent: answer with charts drawn in the Python sandbox - #140

Merged
utkarsh5026 merged 2 commits into
mainfrom
ccr-d66f97ce-jo8pu9
Oct 23, 2026
Merged

utkarsh5026 merged 2 commits into
mainfrom
ccr-d66f97ce-jo8pu9

Conversation

@utkarsh5026

Copy link
Copy Markdown
Owner

With AgentView(python="local"), the agent can now read the files it saved
with pandas, draw a chart with matplotlib and put it in the answer with a
new show_chart tool. Charts show under the answer's text in ask(), the chat
window and transcript(), as data: URL pictures that stay in the saved
notebook; save_charts() writes them to files in agent-charts/ (never
replacing one), and answer.charts holds them as data.

  • charts.py: Chart, image_kind (PNG/JPEG/GIF/WebP/SVG by first bytes),
    chart_of (3 MB cap), chart_file_name and write_charts.
  • The local sandbox offers matplotlib by default, on the Agg backend with
    a shared matplotlibrc (quiet axes, a colour-blind-safe categorical
    palette) kept outside the workspace, and a charts/ folder ready.
  • The prompt says when a chart helps and how to make it read; a run that
    draws pictures says how to show them; a new budget limit, charts (8).

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_017hzTza1JyNtxEGug1eV6sw

With AgentView(python="local"), the agent can now read the files it saved
with pandas, draw a chart with matplotlib and put it in the answer with a
new show_chart tool. Charts show under the answer's text in ask(), the chat
window and transcript(), as data: URL pictures that stay in the saved
notebook; save_charts() writes them to files in agent-charts/ (never
replacing one), and answer.charts holds them as data.

- charts.py: Chart, image_kind (PNG/JPEG/GIF/WebP/SVG by first bytes),
  chart_of (3 MB cap), chart_file_name and write_charts.
- The local sandbox offers matplotlib by default, on the Agg backend with
  a shared matplotlibrc (quiet axes, a colour-blind-safe categorical
  palette) kept outside the workspace, and a charts/ folder ready.
- The prompt says when a chart helps and how to make it read; a run that
  draws pictures says how to show them; a new budget limit, charts (8).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hzTza1JyNtxEGug1eV6sw
Charts now come from Altair instead of matplotlib: the model saves a
Vega-Lite chart (chart.save('charts/x.json')) and show_chart has the local
sandbox draw it as SVG with Vega and Vega-Lite, in a fresh Deno with the
same permissions as a run (read access to the cache, no network), so
drawing a chart fetches nothing. The charts are cleaner and crisper, and
the download is smaller (Altair is ~2 MB; matplotlib was ~18 MB).

- charts.py: read_spec refuses a file that isn't a Vega-Lite chart or
  reads a URL; themed_spec moves the title to the caption and drops the
  300x300 size Altair writes into every chart; CHART_THEME is the shared
  look (the colour-blind-safe palette, gridlines on number axes only).
- sandboxes: Vega 6.4.0 and Vega-Lite 6.4.3 pinned by SHA-256 (CDN and
  npm tarball agree), vega_url= for a mirror, charts.mjs draws one chart.
- Workspace gains draws_charts / draw_vega_lite; a workspace without it
  asks the model for a picture, and matplotlib still works when offered.
- save_charts writes each Vega-Lite chart's spec beside its SVG.
- Fix: needed_packages compares lock-file names as pip does, so packages
  whose dependencies are named with '_' or '.' (Altair's) can be offered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hzTza1JyNtxEGug1eV6sw
@utkarsh5026
utkarsh5026 merged commit e6e81dd into main Oct 23, 2026
14 checks passed
@utkarsh5026
utkarsh5026 deleted the ccr-d66f97ce-jo8pu9 branch October 23, 2026 12:21
@utkarsh5026 utkarsh5026 mentioned this pull request Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants