adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Tool use with function calling is unsupported', 'status': 'INVALID_ARGUMENT'}}

Open kevinnkansah opened this issue 1 year ago • 7 comments

I get this error but this is very confusing because Gemini 2.0 does support function calling as per the docs what is happening

from google.adk.agents import LlmAgent, Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools import google_search
from google.adk.tools.agent_tool import AgentTool
from google.genai import types

MODEL = "gemini-2.0-flash"

# Define a summarizer agent
summarizer = LlmAgent(
    name="Summarizer",
    description="Summarizes text.",
    model=MODEL,  # Or your preferred Gemini model
    instruction="You are an expert summarizer. Please read the following text and provide a concise summary of the key points."
)

# Define a web searcher agent
web_searcher = LlmAgent(
    name="WebSearch",
    description="Performs web searches for facts.",
    model=MODEL,  # Or your preferred Gemini model
    instruction="You are a web search expert. When given a topic or question, use the 'google_search' tool to find relevant information. Focus on retrieving factual and reliable sources.",
    tools=[google_search]  # Equip with the built-in Google Search tool
)

# Define the research assistant agent that orchestrates the search and summarization
research_assistant = Agent(
    name="ResearchAssistant",
    description="Finds and summarizes information on a topic.",
    model=MODEL,  # Or your preferred Gemini model
    instruction="You are a research assistant. When the user provides a topic, first use the WebSearch tool to find relevant documents or web pages. Then, use the Summarizer tool to summarize the information you found. Present the summary to the user.",
    sub_agents=[web_searcher, summarizer]  # Equip with the defined subagents
)

# Define a high-level report writer agent that delegates research
report_writer = Agent(
    name="ReportWriter",
    model=MODEL,  # Or your preferred Gemini model
    instruction="You are a report writer. When the user asks you to write a report on a specific topic, delegate the task of gathering and summarizing information to the 'ResearchAssistant' tool. Once you receive the summary, format it into a coherent report for the user.",
    sub_agents=[research_assistant],  # Equip with the defined subagent
)

# The main research agent that the user will interact with
research_agent = report_writer

# This is the entry point that ADK looks for when loading your agent
root_agent = research_agent

APP_NAME = "research_app"
USER_ID = "user123"
SESSION_ID = "session1"

session_service = InMemorySessionService()
session = session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)
runner = Runner(agent=research_agent, app_name=APP_NAME, session_service=session_service)

async def call_agent(query):
    content = types.Content(role='user', parts=[types.Part(text=query)])
    events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content)
    for event in events:
        if event.is_final_response():
            final_response = event.content.parts[0].text
            print("Agent Response:", final_response)

kevinnkansah avatar Apr 12 '25 21:04 kevinnkansah

Do you have the full error trace?

hangfei avatar Apr 12 '25 23:04 hangfei

@hangfei

INFO:     Started server process [22853]
INFO:     Waiting for application startup.
+-----------------------------------------------------------------------------+
| ADK Web Server started                                                      |
|                                                                             |
| For local testing, access at http://localhost:8000.                         |
+-----------------------------------------------------------------------------+

INFO:     Application startup complete.
INFO:     Uvicorn running on http://*******:8000 (Press CTRL+C to quit)
INFO:     *********:43564 - "GET / HTTP/1.1" 307 Temporary Redirect
INFO:     *********:43564 - "GET /dev-ui HTTP/1.1" 200 OK
INFO:     *********:43580 - "GET /main-SLIAU2JL.js HTTP/1.1" 304 Not Modified
INFO:     *********:43564 - "GET /polyfills-FFHMD2TL.js HTTP/1.1" 304 Not Modified
INFO:     *********:43596 - "GET /styles-4VDSPQ37.css HTTP/1.1" 304 Not Modified
INFO:     *********:43596 - "GET /assets/config/runtime-config.json HTTP/1.1" 304 Not Modified
INFO:     *********:43596 - "GET /list-apps?relative_path=./ HTTP/1.1" 200 OK
2025-04-13 12:31:01,013 - INFO - fast_api.py:294 - New session created
INFO:     *********:43596 - "POST /apps/research-agent/users/user/sessions HTTP/1.1" 200 OK
INFO:     *********:43596 - "GET /apps/research-agent/eval_sets HTTP/1.1" 200 OK
INFO:     *********:43596 - "GET /apps/research-agent/users/user/sessions HTTP/1.1" 200 OK
INFO:     *********:43596 - "GET /apps/research-agent/users/user/sessions HTTP/1.1" 200 OK
INFO:     *********:43596 - "POST /run_sse HTTP/1.1" 200 OK
2025-04-13 12:31:04,059 - INFO - envs.py:47 - Loaded .env file for research-agent at /home/kevin/Documents/adk-research-agent/.env
2025-04-13 12:31:04,059 - INFO - envs.py:53 - Reloaded .env file for research-agent at /home/kevin/Documents/adk-research-agent/.env
2025-04-13 12:31:04,113 - INFO - google_llm.py:83 - Sending out request, model: gemini-2.0-flash, backend: ml_dev, stream: False
2025-04-13 12:31:04,114 - INFO - google_llm.py:89 - 
LLM Request:
-----------------------------------------------------------
System Instruction:
You are a report writer. When the user asks you to write a report on a specific topic, delegate the task of gathering and summarizing information to the 'ResearchAssistant' tool. Once you receive the summary, format it into a coherent report for the user.

You are an agent. Your internal name is "ReportWriter".


You have a list of other agents to transfer to:


Agent name: ResearchAssistant
Agent description: Finds and summarizes information on a topic.


If you are the best to answer the question according to your description, you
can answer it.

If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transfering, do not generate any text other than
the function call.

-----------------------------------------------------------
Contents:
{"parts":[{"text":"hI"}],"role":"user"}
-----------------------------------------------------------
Functions:
transfer_to_agent: {'agent_name': {'type': <Type.STRING: 'STRING'>}} -> None
-----------------------------------------------------------

2025-04-13 12:31:04,114 - INFO - models.py:6423 - AFC is enabled with max remote calls: 10.
2025-04-13 12:31:05,285 - INFO - _client.py:1740 - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent "HTTP/1.1 200 OK"
2025-04-13 12:31:05,295 - INFO - google_llm.py:145 - 
LLM Response:
-----------------------------------------------------------
Text:
Hello! How can I help you today?

-----------------------------------------------------------
Function calls:

-----------------------------------------------------------
Raw response:
{"candidates":[{"content":{"parts":[{"text":"Hello! How can I help you today?\n"}],"role":"model"},"finish_reason":"STOP","avg_logprobs":-0.021260035037994385}],"model_version":"gemini-2.0-flash","usage_metadata":{"candidates_token_count":10,"candidates_tokens_details":[{"modality":"TEXT","token_count":10}],"prompt_token_count":185,"prompt_tokens_details":[{"modality":"TEXT","token_count":185}],"total_token_count":195},"automatic_function_calling_history":[]}
-----------------------------------------------------------

2025-04-13 12:31:05,296 - INFO - fast_api.py:613 - Generated event in agent run streaming: {"content":{"parts":[{"text":"Hello! How can I help you today?\n"}],"role":"model"},"invocation_id":"e-************************************","author":"ReportWriter","actions":{"state_delta":{},"artifact_delta":{},"requested_auth_configs":{}},"id":"B1qiH6r0","timestamp":1744540264.07067}
INFO:     *********:43596 - "GET /apps/research-agent/users/user/sessions/************************************ HTTP/1.1" 200 OK
INFO:     *********:50214 - "POST /run_sse HTTP/1.1" 200 OK
2025-04-13 12:31:25,999 - INFO - google_llm.py:83 - Sending out request, model: gemini-2.0-flash, backend: ml_dev, stream: False
2025-04-13 12:31:25,999 - INFO - google_llm.py:89 - 
LLM Request:
-----------------------------------------------------------
System Instruction:
You are a report writer. When the user asks you to write a report on a specific topic, delegate the task of gathering and summarizing information to the 'ResearchAssistant' tool. Once you receive the summary, format it into a coherent report for the user.

You are an agent. Your internal name is "ReportWriter".


You have a list of other agents to transfer to:


Agent name: ResearchAssistant
Agent description: Finds and summarizes information on a topic.


If you are the best to answer the question according to your description, you
can answer it.

If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transfering, do not generate any text other than
the function call.

-----------------------------------------------------------
Contents:
{"parts":[{"text":"hI"}],"role":"user"}
{"parts":[{"text":"Hello! How can I help you today?\n"}],"role":"model"}
{"parts":[{"text":"i need information about the latest UCL fixtures and predictions"}],"role":"user"}
-----------------------------------------------------------
Functions:
transfer_to_agent: {'agent_name': {'type': <Type.STRING: 'STRING'>}} -> None
-----------------------------------------------------------

2025-04-13 12:31:25,999 - INFO - models.py:6423 - AFC is enabled with max remote calls: 10.
2025-04-13 12:31:27,354 - INFO - _client.py:1740 - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent "HTTP/1.1 200 OK"
2025-04-13 12:31:27,355 - WARNING - types.py:3082 - Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts,check out the non text parts for full response from model.
2025-04-13 12:31:27,356 - INFO - google_llm.py:145 - 
LLM Response:
-----------------------------------------------------------
Text:
I can write a report about the latest UCL fixtures and predictions, but first, I need to gather the information. I will transfer this request to the ResearchAssistant.


-----------------------------------------------------------
Function calls:
name: transfer_to_agent, args: {'agent_name': 'ResearchAssistant'}
-----------------------------------------------------------
Raw response:
{"candidates":[{"content":{"parts":[{"text":"I can write a report about the latest UCL fixtures and predictions, but first, I need to gather the information. I will transfer this request to the ResearchAssistant.\n\n"},{"function_call":{"args":{"agent_name":"ResearchAssistant"},"name":"transfer_to_agent"}}],"role":"model"},"finish_reason":"STOP","avg_logprobs":-0.11377541585402055}],"model_version":"gemini-2.0-flash","usage_metadata":{"candidates_token_count":44,"candidates_tokens_details":[{"modality":"TEXT","token_count":44}],"prompt_token_count":205,"prompt_tokens_details":[{"modality":"TEXT","token_count":205}],"total_token_count":249},"automatic_function_calling_history":[]}
-----------------------------------------------------------

2025-04-13 12:31:27,356 - INFO - fast_api.py:613 - Generated event in agent run streaming: {"content":{"parts":[{"text":"I can write a report about the latest UCL fixtures and predictions, but first, I need to gather the information. I will transfer this request to the ResearchAssistant.\n\n"},{"functionCall":{"id":"adk-************************************","args":{"agent_name":"ResearchAssistant"},"name":"transfer_to_agent"}}],"role":"model"},"invocation_id":"e-************************************","author":"ReportWriter","actions":{"state_delta":{},"artifact_delta":{},"requested_auth_configs":{}},"long_running_tool_ids":[],"id":"9BUjMcB1","timestamp":1744540285.939834}
2025-04-13 12:31:27,357 - INFO - fast_api.py:613 - Generated event in agent run streaming: {"content":{"parts":[{"functionResponse":{"id":"adk-************************************","name":"transfer_to_agent","response":{}}}],"role":"user"},"invocation_id":"e-************************************","author":"ReportWriter","actions":{"state_delta":{},"artifact_delta":{},"transfer_to_agent":"ResearchAssistant","requested_auth_configs":{}},"id":"TcLu314I","timestamp":1744540287.356908}
2025-04-13 12:31:27,396 - INFO - google_llm.py:83 - Sending out request, model: gemini-2.0-flash, backend: ml_dev, stream: False
2025-04-13 12:31:27,397 - INFO - google_llm.py:89 - 
LLM Request:
-----------------------------------------------------------
System Instruction:
You are a research assistant. When the user provides a topic, first use the WebSearch tool to find relevant documents or web pages. Then, use the Summarizer tool to summarize the information you found. Present the summary to the user.

You are an agent. Your internal name is "ResearchAssistant".

 The description about you is "Finds and summarizes information on a topic."


You have a list of other agents to transfer to:


Agent name: WebSearch
Agent description: Performs web searches for facts.


Agent name: Summarizer
Agent description: Summarizes text.


Agent name: ReportWriter
Agent description: 


If you are the best to answer the question according to your description, you
can answer it.

If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transfering, do not generate any text other than
the function call.

Your parent agent is ReportWriter. If neither the other agents nor
you are best for answering the question according to the descriptions, transfer
to your parent agent. If you don't have parent agent, try answer by yourself.

-----------------------------------------------------------
Contents:
{"parts":[{"text":"hI"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ReportWriter] said: Hello! How can I help you today?\n"}],"role":"user"}
{"parts":[{"text":"i need information about the latest UCL fixtures and predictions"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ReportWriter] said: I can write a report about the latest UCL fixtures and predictions, but first, I need to gather the information. I will transfer this request to the ResearchAssistant.\n\n"},{"text":"[ReportWriter] called tool `transfer_to_agent` with parameters: {'agent_name': 'ResearchAssistant'}"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ReportWriter] `transfer_to_agent` tool returned result: {}"}],"role":"user"}
-----------------------------------------------------------
Functions:
transfer_to_agent: {'agent_name': {'type': <Type.STRING: 'STRING'>}} -> None
-----------------------------------------------------------

2025-04-13 12:31:27,397 - INFO - models.py:6423 - AFC is enabled with max remote calls: 10.
2025-04-13 12:31:28,336 - INFO - _client.py:1740 - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent "HTTP/1.1 200 OK"
2025-04-13 12:31:28,338 - WARNING - types.py:3082 - Warning: there are non-text parts in the response: ['function_call'],returning concatenated text result from text parts,check out the non text parts for full response from model.
2025-04-13 12:31:28,338 - INFO - google_llm.py:145 - 
LLM Response:
-----------------------------------------------------------
Text:
None
-----------------------------------------------------------
Function calls:
name: transfer_to_agent, args: {'agent_name': 'WebSearch'}
-----------------------------------------------------------
Raw response:
{"candidates":[{"content":{"parts":[{"function_call":{"args":{"agent_name":"WebSearch"},"name":"transfer_to_agent"}}],"role":"model"},"finish_reason":"STOP","avg_logprobs":-0.011882495880126954}],"model_version":"gemini-2.0-flash","usage_metadata":{"candidates_token_count":10,"candidates_tokens_details":[{"modality":"TEXT","token_count":10}],"prompt_token_count":384,"prompt_tokens_details":[{"modality":"TEXT","token_count":384}],"total_token_count":394},"automatic_function_calling_history":[]}
-----------------------------------------------------------

2025-04-13 12:31:28,339 - INFO - fast_api.py:613 - Generated event in agent run streaming: {"content":{"parts":[{"functionCall":{"id":"adk-************************************","args":{"agent_name":"WebSearch"},"name":"transfer_to_agent"}}],"role":"model"},"invocation_id":"e-************************************","author":"ResearchAssistant","actions":{"state_delta":{},"artifact_delta":{},"requested_auth_configs":{}},"long_running_tool_ids":[],"id":"LoB08Khh","timestamp":1744540287.357733}
2025-04-13 12:31:28,339 - INFO - fast_api.py:613 - Generated event in agent run streaming: {"content":{"parts":[{"functionResponse":{"id":"adk-************************************","name":"transfer_to_agent","response":{}}}],"role":"user"},"invocation_id":"e-************************************","author":"ResearchAssistant","actions":{"state_delta":{},"artifact_delta":{},"transfer_to_agent":"WebSearch","requested_auth_configs":{}},"id":"emVQbABp","timestamp":1744540288.339786}
2025-04-13 12:31:28,385 - INFO - google_llm.py:83 - Sending out request, model: gemini-2.0-flash, backend: ml_dev, stream: False
2025-04-13 12:31:28,385 - INFO - google_llm.py:89 - 
LLM Request:
-----------------------------------------------------------
System Instruction:
You are a web search expert. When given a topic or question, use the 'google_search' tool to find relevant information. Focus on retrieving factual and reliable sources.

You are an agent. Your internal name is "WebSearch".

 The description about you is "Performs web searches for facts."


You have a list of other agents to transfer to:


Agent name: ResearchAssistant
Agent description: Finds and summarizes information on a topic.


Agent name: Summarizer
Agent description: Summarizes text.


If you are the best to answer the question according to your description, you
can answer it.

If another agent is better for answering the question according to its
description, call `transfer_to_agent` function to transfer the
question to that agent. When transfering, do not generate any text other than
the function call.

Your parent agent is ResearchAssistant. If neither the other agents nor
you are best for answering the question according to the descriptions, transfer
to your parent agent. If you don't have parent agent, try answer by yourself.

-----------------------------------------------------------
Contents:
{"parts":[{"text":"hI"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ReportWriter] said: Hello! How can I help you today?\n"}],"role":"user"}
{"parts":[{"text":"i need information about the latest UCL fixtures and predictions"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ReportWriter] said: I can write a report about the latest UCL fixtures and predictions, but first, I need to gather the information. I will transfer this request to the ResearchAssistant.\n\n"},{"text":"[ReportWriter] called tool `transfer_to_agent` with parameters: {'agent_name': 'ResearchAssistant'}"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ReportWriter] `transfer_to_agent` tool returned result: {}"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ResearchAssistant] called tool `transfer_to_agent` with parameters: {'agent_name': 'WebSearch'}"}],"role":"user"}
{"parts":[{"text":"For context:"},{"text":"[ResearchAssistant] `transfer_to_agent` tool returned result: {}"}],"role":"user"}
-----------------------------------------------------------
Functions:
transfer_to_agent: {'agent_name': {'type': <Type.STRING: 'STRING'>}} -> None
-----------------------------------------------------------

2025-04-13 12:31:28,385 - INFO - models.py:6423 - AFC is enabled with max remote calls: 10.
2025-04-13 12:31:28,847 - INFO - _client.py:1740 - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent "HTTP/1.1 400 Bad Request"
2025-04-13 12:31:28,863 - ERROR - fast_api.py:616 - Error in event_generator: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Tool use with function calling is unsupported', 'status': 'INVALID_ARGUMENT'}}
Traceback (most recent call last):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/cli/fast_api.py", line 605, in event_generator
    async for event in runner.run_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/runners.py", line 197, in run_async
    async for event in invocation_context.agent.run_async(invocation_context):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 141, in run_async
    async for event in self._run_async_impl(ctx):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 232, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 231, in run_async
    async for event in self._run_one_step_async(invocation_context):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 261, in _run_one_step_async
    async for event in self._postprocess_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 329, in _postprocess_async
    async for event in self._postprocess_handle_function_calls_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 419, in _postprocess_handle_function_calls_async
    async for event in agent_to_run.run_async(invocation_context):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 141, in run_async
    async for event in self._run_async_impl(ctx):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 232, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 231, in run_async
    async for event in self._run_one_step_async(invocation_context):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 261, in _run_one_step_async
    async for event in self._postprocess_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 329, in _postprocess_async
    async for event in self._postprocess_handle_function_calls_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 419, in _postprocess_handle_function_calls_async
    async for event in agent_to_run.run_async(invocation_context):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 141, in run_async
    async for event in self._run_async_impl(ctx):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 232, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 231, in run_async
    async for event in self._run_one_step_async(invocation_context):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 257, in _run_one_step_async
    async for llm_response in self._call_llm_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 470, in _call_llm_async
    async for llm_response in llm.generate_content_async(
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/models/google_llm.py", line 140, in generate_content_async
    response = await self.api_client.aio.models.generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/genai/models.py", line 6429, in generate_content
    response = await self._generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/genai/models.py", line 5431, in _generate_content
    response_dict = await self._api_client.async_request(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/genai/_api_client.py", line 708, in async_request
    result = await self._async_request(http_request=http_request, stream=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/genai/_api_client.py", line 652, in _async_request
    await errors.APIError.raise_for_async_response(response)
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/genai/errors.py", line 129, in raise_for_async_response
    raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Tool use with function calling is unsupported', 'status': 'INVALID_ARGUMENT'}}
2025-04-13 12:31:28,865 - ERROR - __init__.py:157 - Failed to detach context
Traceback (most recent call last):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/trace/__init__.py", line 587, in use_span
    yield span
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/sdk/trace/__init__.py", line 1105, in start_as_current_span
    yield span
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/trace/__init__.py", line 452, in start_as_current_span
    yield span
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 487, in _call_llm_async
    yield llm_response
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x7f4dc2ab1210> at 0x7f4db9a94d40> was created in a different Context
2025-04-13 12:31:28,866 - ERROR - __init__.py:157 - Failed to detach context
Traceback (most recent call last):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/trace/__init__.py", line 587, in use_span
    yield span
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/sdk/trace/__init__.py", line 1105, in start_as_current_span
    yield span
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/trace/__init__.py", line 452, in start_as_current_span
    yield span
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 487, in _call_llm_async
    yield llm_response
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "/home/kevin/Documents/adk-research-agent/.venv/lib/python3.12/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x7f4dc2ab1210> at 0x7f4db9a79380> was created in a different Context
INFO:     *********:50214 - "GET /apps/research-agent/users/user/sessions/************************************ HTTP/1.1" 200 OK

kevinnkansah avatar Apr 13 '25 10:04 kevinnkansah

@kevinnkansah try changing:

events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content)

To:

events = runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=content)

Let me know if that fixes it for you

IAmNo1Special avatar Apr 13 '25 21:04 IAmNo1Special

@IAmNo1Special it did not change anything, this must be a bug, @hangfei

kevinnkansah avatar Apr 14 '25 07:04 kevinnkansah

Same Issue, even if i use gemini-2.5-pro-exp-03-25

Image

kevinnkansah avatar Apr 14 '25 07:04 kevinnkansah

Thanks for raising this! I faced the same issue and after some investigation, here’s what I believe is happening — hope it helps clarify the underlying mechanism:

The problem seems to stem from how ADK handles function calling + tool usage in the same interaction turn. Specifically: • When a sub-agent is registered using the sub_agents parameter, it’s exposed to the orchestrating LLM as a function. • When this function (i.e., the sub-agent) is invoked by the orchestrator, the LLM is effectively issuing a function_call. • However, once inside that function-called context, the sub-agent is no longer allowed to invoke any tools, such as google_search.

Even though the sub-agent is properly configured with tools, the ADK backend seems to block any tool use from within a function execution context. This results in the error:

400 INVALID_ARGUMENT: Tool use with function calling is unsupported

This becomes a limitation when you’re trying to design modular agent architectures, where each sub-agent handles a specific responsibility (e.g. a search agent, a calculator agent). With the current behavior, sub-agents lose access to their tools when invoked through the orchestrator.

I detailed this in issue https://github.com/google/adk-python/issues/53 as well, including a reproduction case and suggestions. Hope this helps the team better understand and prioritize a fix or official workaround.

Let me know if you’ve found any alternate solution!

nelsonfrugeri-tech avatar Apr 14 '25 13:04 nelsonfrugeri-tech

Okay, I understand, hopefullly the issue gets resolved. I have seen the workaround in #53 . I will close this issue

kevinnkansah avatar Apr 14 '25 14:04 kevinnkansah