Description
Describe the bug
When building a basic agent application with Google's Agent Development Kit (Python)(ADK) with the Google.GenAI backend (e.g., via Google AI Studio, not Vertex AI), uploading a file (e.g., a PDF) results in an error if the display_name
attribute is present in the file part of the request. The Google AI Studio backend does not support display_name for file uploads, leading to a request failure.
I did a bit of digging and the provided code for the relevant class in google_llm.py has a method called _preprocess_request
that adjusts the LlmRequest
for backend-specific compatibility. Currently, this method sets llm_request.config.labels = None
when the backend is GoogleLLMVariant.GEMINI_API
because labels are not supported. This is exactly what we want, however, a similar modification will need to be made within the _preprocess_request
to iterate over each Part
in the llm_request
and check for the one that represents file uploads (and the respective key of display_name
which should be sanitized out or set to None or something)
tldr; If a file part contains a display_name
and the backend is GoogleLLMVariant.GEMINI_API, the display_name attribute should be removed or set to None before sending the request to the model. Or don't add it in the first place.
As it stands, there is no way around this I can find without changes to the actual adk-python
codebase. If I'm wrong please let me know.
To Reproduce
- Configure an agent to use a Gemini model via the Google.GenAI backend (with API key from Google AI Studio).
- Use a tool or agent step that involves uploading a file (e.g., a PDF). The ADK by default might (I'm still not sure but this is my assumption) include
display_name
when constructing the FileData part. - Invoke the agent, for example, through
adk web
(I'm following this example: https://github.com/google/adk-samples/tree/main/python/agents/academic-research) by uploading a relevant file and sending a message that triggers the file processing. - Observe the error in the ADK logs or server response, indicating that
display_name
is an unsupported parameter.
Expected behavior
The ADK should automatically preprocess requests to the Google.GenAI backend to ensure compatibility. Specifically, the display_name
attribute should be removed (or not added in the first place) from file parts in the contents of an LlmRequest
if the determined backend is GoogleLLMVariant.GEMINI_API
. This is similar to how labels are already handled in Gemini._preprocess_request()
in google/adk/models/google_llm.py
.
Actual behavior
The display_name
attribute is passed to the Google AI Studio backend, which does not support it, causing an API error and preventing successful file processing.
Screenshots or Logs
Traceback (most recent call last):
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/adk/cli/fast_api.py", line 713, in event_generator
async for event in runner.run_async(
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/adk/runners.py", line 197, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.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 "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/adk/agents/llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.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 "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 314, in _run_one_step_async
async for llm_response in self._call_llm_async(
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 539, in _call_llm_async
async for llm_response in llm.generate_content_async(
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/adk/models/google_llm.py", line 162, in generate_content_async
response = await self.api_client.aio.models.generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 7453, in generate_content
response = await self._generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 6423, in _generate_content
request_dict = _GenerateContentParameters_to_mldev(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 928, in _GenerateContentParameters_to_mldev
[
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 929, in <listcomp>
_Content_to_mldev(api_client, item, to_object)
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 169, in _Content_to_mldev
[
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 170, in <listcomp>
_Part_to_mldev(api_client, item, to_object)
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 112, in _Part_to_mldev
_Blob_to_mldev(
File "/Users/dschettler/PycharmProjects/google-adk-agent-demo/.venv/lib/python3.11/site-packages/google/genai/models.py", line 61, in _Blob_to_mldev
raise ValueError('display_name parameter is not supported in Gemini API.')
Environment (please complete the following information):
OS: macOS
Python version: 3.11
ADK version: 1.2.1
google-generativeai library version: 0.8.5
This issue affects users trying to leverage file upload capabilities (e.g., for RAG with PDFs) with models hosted on Google AI Studio through the ADK. Let me know if I can help or provide more details.