Repository navigation
Agent: answer with charts drawn in the Python sandbox - #140
Merged
Merged
Conversation
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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
chart_of (3 MB cap), chart_file_name and write_charts.
a shared matplotlibrc (quiet axes, a colour-blind-safe categorical
palette) kept outside the workspace, and a charts/ folder ready.
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