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

Tool use with function calling is unsupported

Open nelsonfrugeri-tech opened this issue 1 year ago • 24 comments

Title: ADK Error: Tool use with function calling is unsupported when using sub_agents with tools like google_search

Component:* Agent Development Kit (ADK)

Description:* It is currently not possible to successfully run an agent orchestration flow within the ADK where a sub_agent (invoked by a primary LlmAgent) is configured with certain built-in tools, specifically tested with google_search. Attempting this pattern consistently results in a 400 INVALID_ARGUMENT error with the message Tool use with function calling is unsupported.

Underlying Mechanism & Problem: When an LlmAgent (acting as an orchestrator) is configured with sub_agents, the ADK framework implicitly uses a function calling mechanism to delegate tasks. The orchestrator's LLM is presented with the sub_agents as available functions/tools. When the orchestrator decides to invoke a specific sub_agent, it effectively makes an internal "function call" (similar conceptually to the transfer_to_agent function, but handled internally by the sub_agents list). The issue arises immediately after this internal function call activates the sub_agent. If the activated sub_agent is configured with a tool like google_search and needs to use it to fulfill the request delegated to it, the underlying API rejects this sequence, returning the 400 INVALID_ARGUMENT - Tool use with function calling is unsupported error. This indicates a conflict where the API cannot handle a state transition from being activated via function calling directly into using a built-in tool like google_search within the same interaction turn for the sub-agent.

Steps to Reproduce:*

  1. Define Agents: Create at least two LlmAgent classes:

    • An AgentOrchestrator configured with sub_agents.
    • An AgentSearch configured with tools=[google_search].
    from google.adk.agents.llm_agent import LlmAgent
    from google.adk.tools import google_search
    
    class AgentSearch(LlmAgent):
        def __init__(self):
            super().__init__(
                name="AgentSearch",
                description="Agent to answer questions using Google Search.",
                instruction="You're an agent that can search the internet for informatio.",
                model="gemini-2.0-flash-exp",
                tools=[google_search],
            )
    
    class AgentOrchestrator(LlmAgent):
        def __init__(self):
            super().__init__(
                name="AgentOrchestrator",
                description="Agent responsible for orchestrating multiple agents",
                instruction="You're an agent orchestrator, you can use your agents to get to the end result and serve the user",
                model="gemini-1.5-pro",
                sub_agents=[AgentSearch(), AgentCalculation()],
            )
    

Expected Behavior: The AgentOrchestrator should successfully delegate the task to the AgentSearch sub-agent via the internal function call mechanism. AgentSearch should then be able to execute its configured google_search tool, retrieve information, and formulate a response, which is then passed back through the orchestrator. Actual Behavior: The process fails when the sub-agent (AgentSearch) configured with google_search is invoked by the orchestrator. The following error is raised:

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

Motivation & Importance: In real-world agent development, it is very common to create specialized agents that use tools like google_search to perform tasks such as retrieving web data. A natural and intuitive use case is to include such an agent as a sub_agent in an orchestrated flow. The ability to use a tool like google_search inside an agent that is invoked as a sub_agent is essential for building modular, composable, and reusable agent architectures. This is a basic and expected pattern when working with tools in the ADK, and limitations here make it harder to adopt simple and effective orchestration designs.

Final Note: I would like to understand if this limitation is known or if there is any provision for allowing the use of tools such as google_search within agents used as sub_agents. If there is any recommended workaround, it would be great to receive this guidance.

nelsonfrugeri-tech avatar Apr 10 '25 22:04 nelsonfrugeri-tech

Same here!

cgoncalves94 avatar Apr 11 '25 02:04 cgoncalves94

same here!

wangmingjunabc avatar Apr 11 '25 09:04 wangmingjunabc

I would also like to know that...

alenowak avatar Apr 11 '25 14:04 alenowak

Thanks for the detailed reproduction steps. We are looking into.

hangfei avatar Apr 12 '25 00:04 hangfei

I'm not sure if it's the same case, but I'm getting the "400 INVALID ARGUMENT" error also if I try to use the "google_search" tool alongside some function tools in the same agent.

marcolardera avatar Apr 12 '25 15:04 marcolardera

Agent_Search = Agent(
    model='gemini-2.0-flash-exp',
    name='SearchAgent',
    instruction="""
    You're a spealist in Google Search
    """,
    tools=[google_search]
)
Agent_Code = Agent(
    model='gemini-2.0-flash-exp',
    name='CodeAgent',
    instruction="""
    You're a specialist in Code Execution
    """,
    tools=[built_in_code_execution]
)
root_agent = Agent(
    name="RootAgent",
    model="gemini-2.0-flash-exp",
    description="Root Agent",
    tools=[agent_tool.AgentTool(agent=Agent_Search), agent_tool.AgentTool(agent=Agent_Code)]
)

This works for me.

The issue might be the api allows one tool to call at-a-time.

Image

Image

KVNAditya2002 avatar Apr 12 '25 16:04 KVNAditya2002

At the moment, Gemini only support one built-in tools.

Right now, please use @KVNAditya 's workaround.

cc: @polong-lin

hangfei avatar Apr 13 '25 01:04 hangfei

Update our docs here to reflect this: https://github.com/google/adk-docs/pull/56

hangfei avatar Apr 13 '25 01:04 hangfei

Thank you @hangfei , I managed to do it using the workaround suggested by @KVNAditya (making a separate Agent for web searching and adding it do the root one using AgentTool)

However, I think this behaviour is rather counterintuitive and that we should be allowed to use function tools and built in tools in the same agent. In understand, however, that this limitation comes from Gemini itself and may not be easy to change...

marcolardera avatar Apr 13 '25 08:04 marcolardera

It works!

class AgentOrchestrator(LlmAgent):
    def __init__(self):
        super().__init__(
            name="AgentOrchestrator",
            description="Agent responsible for orchestrating multiple agents",
            instruction="You're an agent orchestrator, you can use your agents to get to the end result and serve the user",
            model="gemini-2.0-flash",
            tools=[agent_tool.AgentTool(agent=AgentCalculation()), agent_tool.AgentTool(agent=AgentSearch())]
        )

Thanks KVNAditya

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

According to my observation so far the core issue arises when we provide additional tools along side a built-In tool to an agent

moazzam-qureshi avatar Apr 15 '25 08:04 moazzam-qureshi

Same Issue

jewells77 avatar Apr 17 '25 08:04 jewells77

According to my observation so far the core issue arises when we provide additional tools along side a built-In tool to an agent

Has someone found a way to do this?

mindadeepam avatar Apr 21 '25 18:04 mindadeepam

As @hangfei has said above, only one tool is supported at a time. There is a way that is to make an agent that has two subagents, the first does the google search, and then the second takes that message result and does something with it.

But what if you do NOT want the result of the search to be returned as a message at all but, perhaps, saved to a file, for example? Or maybe you have set up a frontend for your application to which you cannot send messages or those messages will end up being sent to the final user when it should only be internal right? Well, you can't. Until this gets changed you pretty much cannot have an agent search AND additional functions in the same agent

alesstracker21 avatar Apr 24 '25 08:04 alesstracker21

As @hangfei has said above, only one tool is supported at a time. There is a way that is to make an agent that has two subagents, the first does the google search, and then the second takes that message result and does something with it.

But what if you do NOT want the result of the search to be returned as a message at all but, perhaps, saved to a file, for example? Or maybe you have set up a frontend for your application to which you cannot send messages or those messages will end up being sent to the final user when it should only be internal right? Well, you can't. Until this gets changed you pretty much cannot have an agent search AND additional functions in the same agent

I'm dealing with the same issue. A potential solution comes to mind but I have not tried it yet. Since this seems to be a limitation with built in tools (or built in search tool?), a workaround could be to use other search tools:

https://docs.crewai.com/tools/serperdevtool https://google.github.io/adk-docs/tools/third-party-tools/#example-web-search-using-crewais-serper-api

navidf avatar May 03 '25 05:05 navidf

Was this ever fixed or will it be? The work around only works with ADK which is paid and I'm only using the Gemini genai SDK. So this doesn't work for me but still has the same issue.

keneficka avatar Sep 20 '25 02:09 keneficka

Any idea if this is ever going to be resolved? I'm getting this error in langchainjs as well

fridaystreet avatar Oct 29 '25 09:10 fridaystreet

Any idea if this is ever going to be resolved? I'm getting this error in langchainjs as well

@fridaystreet I'm not familiar with langchain but I did manage to create a work around for this using the genai SDK. I was not able to use the work around above because I am not using the ADK, so I created an agent with the google search tool and created a function call to call the agent with a function declaration. Like this:

//Search Agent Function
export async function webSearch(query) {
    const response = await ai.models.generateContent({
        model: "gemini-2.5-flash",
        contents: query,
        config: {
            tools: [{googleSearch: {}}]
        },
    });
    
    console.log(response.text);
    return response.text;
}
//The Function Declaration for Actual Agent
export const webSearchFunctionDeclaration = {
  name: "web_search",
  description: "This uses a sub-agent to perform web searches. Use this when a user's request requires or would be aided by additional information from the web. Keep in mind the user won't see the results directly. You will have to pass along or use the relevant information as instructed or requested by the user.",
  parameters: {
      type: Type.OBJECT,
      properties: {
          query: {
            type: Type.STRING,
            description: "The text for the web search."
          }
      },
      required: ['query']
  }
};

Not sure if this helps for your situation.

keneficka avatar Oct 30 '25 00:10 keneficka

This setup currently works for me

any_tool = AgentTool(agent=any_agent)
search_tool = AgentTool(agent=search_agent)

root_agent = Agent(
    name="agent",
    tools=[
        anytool,
        search_tool,
    ],
)

HectorGitt avatar Nov 08 '25 01:11 HectorGitt

Was anyone able to make @KVNAditya 's or another workaround work with remote agents -RemoteA2aAgent - objects?

EDIT: nvm, separating the product_catalog_agent into two agents - one with the function get_product_info and another with the built-in google_search tool worked, as the workaround suggests:

# ... same as below ...

customer_support_agent = LlmAgent(
    model=Gemini(model="gemini-2.5-flash-lite", retry_options=retry_config),
    name="customer_support_agent",
    description="...",
    instruction="""
    ...
    """,
    tools=[AgentTool(remote_product_catalog_agent), AgentTool(remote_search_agent)]

Though this still does feel very limiting, because this means building an agent to be used a subagent or as an independent agent can require different architecture, since in this case the remote_product_catalog_agent can't use built-in tools, such as Google search.

Original code that I'd expect to work but throws the 400 Tool use with function calling is unsupported error described in the original issue 👇

# Server

product_catalog_agent = LlmAgent(
    model=Gemini(model="gemini-2.5-flash-lite", retry_options=retry_config),
    name="product_catalog_agent",
    description="...",
    instruction="""
    ...
    """,
    tools=[get_product_info, google_search],
)

# Create the A2A app
app = to_a2a(product_catalog_agent, port=8001)

###

# Client

remote_product_catalog_agent = RemoteA2aAgent(
    name="product_catalog_agent",
    description="...",
    agent_card=f"http://localhost:8001{AGENT_CARD_WELL_KNOWN_PATH}",
)

customer_support_agent = LlmAgent(
    model=Gemini(model="gemini-2.5-flash-lite", retry_options=retry_config),
    name="customer_support_agent",
    description="...",
    instruction="""
    ...
    """,
    sub_agents=[remote_product_catalog_agent]
    # , tools=[AgentTool(remote_product_catalog_agent)] # ⚠️ Same error happens when it's added as a tool, though the top-level agent then fails silently
)

The-Pavel avatar Nov 23 '25 00:11 The-Pavel