I want to generate charts through ADK multi-agents located in Agent engine and show them to the users as agent responses. I guess that I need to save them into the cloud storage, since files inside Agent-engine are not available. Any tips or sample codes for it?
Hey @soonho.kim
cool question for the Build with AI > Agents channel!
To manage your chart data and assets, use the Artifact Service in the ADK, pointing it to your Cloud Storage bucket: Artifact Service Documentation.
For building the charts dynamically, definitely leverage our recently released Agent Engine Code Execution. This lets your agent run Python code to generate visualizations. Check the sample here: Code Execution Notebook.
Let me know your results. I can quickly build a dedicated sample if needed!
Hi ,
I am trying to plot graph from the downloaded data using the following code.
plot_agent = Agent(
model='gemini-2.5-flash',
name='plot_agent',
description="""You are an agent who can generate graphs for data.""",
instruction="""
Steps involved:
1) Ask the user for the stock symbol.
2) Pass this stock symbol to the tool load_stock_data. The tool returns the stock data as a CSV string.
3) \*\*CODE EXECUTION REQUIRED\*\*: You must generate a Python code block to perform the following:
a. Read the input CSV string into a pandas DataFrame (df).
b. Convert the 'DATE' column to datetime.
c. Plot a line graph of the 'CLOSE' column over time.
d. Set the title of the graph.
e. \*\*CRITICAL\*\*: Save the plot to a file named 'plot.png' using plt.savefig('plot.png').
4) Once the graph is successfully saved, include the image artifact ('plot.png') in your final, natural language response to the user.
""",
tools=[load_stock_data],
code_executor=VertexAiCodeExecutor(
optimize_data_file=True,
stateful=True,
return_artifacts=True
)
)
Data is being downloaded and the graph is also generated as the Agent is able to analyze the graph and provide a summary, but unable to display the graph in the UI.
@ilnardo92 I am also interested in generating a chart via agent. What’s the current limitation? Can we also generate an interactive chart and show in the Chat UI e.g., create a blob of HTML based on plotly or vega?
reference:
@soonho.kim I got some luck with GcsArtifactService and BuiltInCodeExecutor
use GcsArtifactService as the artifact service , and BuiltInCodeExecutor to give coding and plotting capability to the agent.
then in the reponses you will see Saved as artifact: 20251121_095500.png. , somthing like this
(you have to print all the parts of the response event).
now if you go to bucket that you used for the GcsArtifactService , you can find the plot as png. you can fetch it and display.
there must be a better way , it suppose to be load artifacts from artifact service in the tool call back, for some reason BuiltInCodeExecutor response does not consider as tool
Thanks so much for all the comments and suggestion!
Finally, I used a python code as tool to generate charts and save them to the cloud storage and share the charts with users. I really appreciate your help!