improvement: extract and deliver chart PNGs from code_run output#5
Open
hjpinheiro wants to merge 1 commit into
Open
improvement: extract and deliver chart PNGs from code_run output#5hjpinheiro wants to merge 1 commit into
hjpinheiro wants to merge 1 commit into
Conversation
The code_run response includes chart artifacts (matplotlib/seaborn plots, etc.) as base64 PNGs in response.artifacts.charts, but these were previously ignored. Now extracts chart PNGs and delivers them as blob messages so users see the rendered charts directly in the chat. Also adds chart metadata (type, title) and charts_count to the JSON response. Additionally adds create_text_message for the text output (previously only JSON was returned, so agents couldn't see the output in chat).
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.
Summary
When Python code generates charts (matplotlib, seaborn, plotly, etc.), the Daytona SDK captures them as base64 PNG images in
response.artifacts.charts. These were previously discarded.This PR extracts the chart PNGs and delivers them as blob messages so users see rendered charts directly in the Dify chat.
Changes
Chart PNG delivery
Chart metadata in JSON response
{ "exit_code": 0, "output": "...", "charts_count": 2, "charts": [{"type": "bar", "title": "Sales by Quarter"}, ...] }Text output
Added
create_text_message(response.result)so the agent sees code output in chat (previously only JSON was returned).SDK structure
The chart data path (verified against
daytona==0.187.0):All field access uses defensive
getattrwithNonedefaults.Testing
py_compilepasses