Replies: 1 comment 1 reply
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: The Hi @Mattylam, Thanks for the detailed question. It seems like you are running into an issue with how the CSV data is being passed to the The The issue with your current approach is that the Here is a suggested approach:
For example, when you invoke your agent, the content should look something like this: from google.genai import types
# Assuming you have the CSV content in a variable called `csv_content`
csv_part = types.Part(
inline_data=types.Blob(
mime_type="text/csv",
data=csv_content
)
)
# The user's prompt or instruction for the agent
prompt_part = types.Part(text="Analyze the attached CSV data and create a plot.")
# Make the call to the agent
response = data_science_agent.run(content=[prompt_part, csv_part]) With this approach, the You can find more details about how Let me know if this helps! [1] https://github.com/google/adk-python/blob/main/src/google/adk/code_executors/vertex_ai_code_executor.py |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
This is a follow-up question from this discussion
I was able to recreate the solution where we pass the csv_artifact as csv content, but that usecase was for using a runner.
My setup:
I have a root agent that talks to the user and transfers the tasks to appropriate agents
One of the sub agent is an analytics agent (similar to this example).
What I am trying to achieve:
I want the sub agent to load appropriate csv files (using the tools I have) and pass them to the VertexAiCodeExecutor to do analysis/plotting on it.
From my research, the best way is to save the artifact, and then load the artifact when needed.
This was my attempt, but failed, the system was able to load the saved csv artifact, the code was able to show, but the system was not able to reference the data.
I have also logged the multiagent communication here. Agent_Communication_report.pdf
`import os
from google.adk.code_executors import VertexAiCodeExecutor
from google.adk.agents import Agent
from google.genai import types
from .prompts import return_instructions_ds
from google.adk.tools import load_artifacts
from google.adk.agents.callback_context import CallbackContext
from google.adk.models import LlmRequest, LlmResponse
add the logger
import logging
logger = logging.getLogger(name)
async def attach_csvs_for_code_exec(
callback_context: CallbackContext, llm_request: LlmRequest
):
"""Attach CSV files to the request for code execution."""
try:
part = await callback_context.load_artifact(filename="table_1.csv")
logger.info(f" CSV ATTACHED to DS Agent")
async def log_code_execution(
callback_context: CallbackContext, llm_response: LlmResponse
):
"""Log generated code and execution results after model response."""
code_detected = False
async def log_tool_execution(
tool, args: dict, tool_context, tool_response: dict
):
"""Log tool execution results, including code execution."""
if hasattr(tool, 'name') and 'code' in tool.name.lower():
logger.info(f"\n⚡ CODE EXECUTION COMPLETED:")
logger.info(f"Tool: {tool.name}")
if tool_response:
logger.info(f"Result: {tool_response}")
return tool_response
local_data_science_agent = Agent(
model=os.getenv("ANALYTICS_AGENT_MODEL"),
name="data_science_agent",
instruction=return_instructions_ds(),
code_executor=VertexAiCodeExecutor(stateful=True, optimize_data_file=True),
before_model_callback=attach_csvs_for_code_exec,
after_model_callback=log_code_execution,
#after_tool_callback=log_tool_execution,
#tools=[load_artifacts],
)
`
Beta Was this translation helpful? Give feedback.
All reactions