-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Issue description
When running an agent that uses the Vertex AI session service at the same time as the GCS artifact service, any agent interaction that results in the creation of an artifact will cause ADK to crash due to a ValueError.
google-adk
version: 1.3.0
google-cloud-aiplatform
version: 1.95.1
Steps to reproduce
- Create an agent (or use a sample agent) that can create artifacts and uses the built-in
load_artifacts
tool. - Ensure that a cloud storage bucket exists with the correct permissions, and ensure that a Reasoning Engine has been created properly for this agent.
- Run:
adk web --artifact_service_uri="gs://{artifact_service_bucket_name}" --session_service_uri="agentengine://projects/{project_number}/locations/{location}/reasoningEngines/{agent_engine_resource_id}"
- After the web service has started, have a conversation with the agent. Tell it to use a tool that will result in the creation of an image or other artifact.
At this point, the artifact has been correctly rendered within the web UI, but ADK will crash when the agent calls the load_artifacts
tool right before returning control to the user. The crash logs look like so:
2025-06-16 15:06:02,478 - INFO - fast_api.py:801 - Generated event in agent run streaming: {"content":{"parts":[...],"role":"user"},"invocationId":"","author":"","actions":{"stateDelta":{...}},"artifactDelta":{"code_execution_image_1.png":0},"requestedAuthConfigs":{}},"id":"","timestamp":1750100761.261922}
2025-06-16 15:06:02,555 - ERROR - fast_api.py:804 - Error in event_generator: too many values to unpack (expected 5)
Traceback (most recent call last):
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/cli/fast_api.py", line 793, in event_generator
async for event in runner.run_async(
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/runners.py", line 198, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/agents/llm_agent.py", line 273, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 282, in run_async
async for event in self._run_one_step_async(invocation_context):
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 302, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 344, in _preprocess_async
await tool.process_llm_request(
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/tools/load_artifacts_tool.py", line 72, in process_llm_request
await self._append_artifacts_to_llm_request(
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/tools/load_artifacts_tool.py", line 79, in _append_artifacts_to_llm_request
artifact_names = await tool_context.list_artifacts()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/tools/tool_context.py", line 76, in list_artifacts
return await self._invocation_context.artifact_service.list_artifact_keys(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[project folder]/.venv/lib/python3.11/site-packages/google/adk/artifacts/gcs_artifact_service.py", line 154, in list_artifact_keys
_, _, _, filename, _ = blob.name.split("/")
^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 5)
Inspection of the program state reveals that blob.name
takes the form of:
"projects/[project_number]/locations/[location]/reasoningEngines/[agent_engine_resource_id]/user/[session_id]/code_execution_image_1.png/0"
Note that this is a different form than when using the GCS artifact service along with the In-Memory (default) session service, which is (at least for now) correctly handled by this code and does not crash.
Expected behaviour
The ADK should not crash when using the Vertex AI/agent engine session service in tandem with the google cloud storage artifact service. Note that if you only use one OR the other of these two services, the crash does not happen.
This bug is caused because the GCS artifact service is hard-coded to expect blob names that take the form [app_name]/[user_id]/[session_id]/[artifact_filename]/[artifact_version]
, which is only true when using the In-Memory session service and not the Vertex AI session service.
Proposed solution
The exact crash happens on line 154 of adk.artifacts.gcs_artifact_service
, in the list_artifact_keys
method while iterating over session_blobs
. The same code is also used on line 162, when iterating over user_namespace_blobs
. The exception is raised because the blob name is split by the forward slash character, and the resulting list is unpacked with the expectation that it has exactly five elements.
The line of code in question is: _, _, _, filename, _ = blob.name.split("/")
Although it would be possible to use conditional logic to try and determine which session service is being used in order to decide on how many values to unpack, I believe this is the wrong approach and would only dig the hard-coded hole deeper. If we assume that the artifact blob name will always end in /[artifact_filename]/[artifact_version]
, then it would be more Pythonic and less error-prone to use starred iterable unpacking.
My proposed change is to replace lines 154/162 like so: *_, filename, _ = blob.name.split("/")
This change will fix the bug immediately, while ensuring that any possible changes to the blob naming conventions down the road will not break the ADK GCS artifact service functionality.