Master Issue: built-in tools cannot co-exist with FunctionDeclaration tools.
Right now, the Gemini server is limited to only one type of tools among the following list:
- Function declaration (mostly used for python function
FunctionTooland other subclass ofBaseTool) - Google Search (Gemini model built-in tool)
- Vertex AI Search (Gemini model built-in tool)
- BuiltInCodeExecutor (Gemini model built-in tool)
- ...
Full list of built-in tools are at https://github.com/googleapis/python-genai/blob/main/google/genai/types.py#L2692
If your agent is using more than one type of tools, currently it is not supported.
Workaround options:
- Use a sub-agent that only carries the built-in tool
- Use AgentTool that only carries the built-in tool and store the response to state for other agents to use.
Could you please clarify the first workaround? I’ve tried to attach a dedicated sub-agent with only this built-in tool to the root agent, but the same error still persists.
search_agent = Agent(
model='gemini-2.0-flash',
name='search_agent',
description="(...)",
instruction="(...)"
tools=[google_search],
)
root_agent = Agent(
name="root_agent",
model="gemini-2.0-flash",
description="(...)",
instruction="(...)"
sub_agents=[weather_agent, search_agent]
Same issue fix this
Right now, it looks like there are no workarounds. I'd appreciate it if you get it fixed ASAP.
Do you have any updates regarding this? I am encountering the following error: fast_api.py:817 - Error in event_generator: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Tool use with function calling is unsupported', 'status': 'INVALID_ARGUMENT'}} @hangfei
I had this working. Hope it helps
search_agent = LlmAgent(
name="basic_search_agent",
model="gemini-2.0-flash",
description="Agent to answer questions using Google Search.",
instruction="I can answer your questions by searching the internet. Just ask me anything!",
tools=[google_search],
)
doc_qa_agent = LlmAgent(
name="doc_qa_agent",
model="gemini-2.0-flash", # Requires Gemini model
tools=[vertex_search_tool],
instruction=f"""You are a helpful assistant that answers questions based on information found in the document store: {YOUR_DATASTORE_ID}.
Use the search tool to find relevant information before answering.
If the answer isn't in the documents, say that you couldn't find the information.
""",
description="Answers questions using a specific Vertex AI Search datastore.",
)
code_agent = LlmAgent(
name="calculator_agent",
model="gemini-2.0-flash",
code_executor=BuiltInCodeExecutor(),
instruction="""You are a calculator agent.
When given a mathematical expression, write and execute Python code to calculate the result.
Return only the final numerical result as plain text, without markdown or code blocks.
""",
description="Executes Python code to perform calculations.",
)
# Wrap the specialized agents as tools
search_tool = AgentTool(agent=search_agent)
doc_qa_tool = AgentTool(agent=doc_qa_agent)
code_tool = AgentTool(agent=code_agent)
# Create the root agent with the search agent
root_agent = LlmAgent(
name="root_agent",
model="gemini-2.0-flash",
tools=[search_tool, doc_qa_tool, code_tool],
instruction="""You are a helpful assistant that can answer questions and perform calculations.
You have 2 specialized agents to choose from:
- basic_search_agent: to search the internet
- doc_qa_agent: to answer questions based on the document store
- calculator_agent: to perform calculations
The user will provide a question which defines where the answer should come from,
and you should delegate to the appropriate agent to find the answer.
""",
description="A helpful assistant that can answer questions and perform calculations."
)
I'm looking to integrate data retrieval from Vertex AI Search into an agent's workflow. Specifically, I need to fetch information using the Vertex AI Search tool and then update the agent's state based on the retrieved data. What's the recommended approach to achieve this?
When I create an agent and try to use a tool for vertex_ai_search and other tool only to save data in state, I got the INVALID_ARGUMENT error also, as mentioned above.
Thanks to @gbmerrall idea https://github.com/google/adk-python/issues/969#issuecomment-2986149575 use search tool wrap up by a agent and a agent tool work. but this have a little problem that AgentTools only return the text content of the agent response generated by llm.
If u need the grounding info like referred webpage or data source , i tried below by override the AgentTool's run_async method and this can bypass the reference as a part o f the agent_tool response and it work.
class CustomAgentToolForGoogleSearch(AgentTool):
@override
async def run_async(
self,
*,
args: dict[str, Any],
tool_context: ToolContext,
) -> Any:
from google.adk.agents.llm_agent import LlmAgent
if self.skip_summarization:
tool_context.actions.skip_summarization = True
if isinstance(self.agent, LlmAgent) and self.agent.input_schema:
input_value = self.agent.input_schema.model_validate(args)
content = types.Content(
role='user',
parts=[
types.Part.from_text(
text=input_value.model_dump_json(exclude_none=True)
)
],
)
else:
content = types.Content(
role='user',
parts=[types.Part.from_text(text=args['request'])],
)
# Use the tool_context directly, bypassing the agent's tools' context
runner = Runner(
app_name=self.agent.name,
agent=self.agent,
artifact_service=ForwardingArtifactService(tool_context),
session_service=InMemorySessionService(),
memory_service=InMemoryMemoryService(),
)
session = await runner.session_service.create_session(
app_name=self.agent.name,
user_id='tmp_user',
state=tool_context.state.to_dict(),
)
last_event = None
async for event in runner.run_async(
user_id=session.user_id, session_id=session.id, new_message=content
):
# Forward state delta to parent session.
if event.actions.state_delta:
tool_context.state.update(event.actions.state_delta)
last_event = event
return last_event
# Agent_Tool original return value as below commented out
# if not last_event or not last_event.content or not last_event.content.parts:
# return ''
# merged_text = '\n'.join(p.text for p in last_event.content.parts if p.text)
# if isinstance(self.agent, LlmAgent) and self.agent.output_schema:
# tool_result = self.agent.output_schema.model_validate_json(
# merged_text
# ).model_dump(exclude_none=True)
# else:
# tool_result = merged_text
# return tool_result
google_search_agent = LlmAgent(
name="google_search_agent_tool",
model="gemini-2.5-flash",
instruction="I can answer your questions by searching the internet. Just ask me anything!",
tools=[google_search],
)
google_search_agent_tool = CustomAgentToolForGoogleSearch(google_search_agent)
This is still happening to me with ADK 1.13. It works sometimes but it gives me error 3/5 times. I am also wrapping google_search tool in a sub agent.
For anyone still facing the issue, check the limitations described here, https://google.github.io/adk-docs/tools/built-in-tools/#bigquery
It works by following this link: https://google.github.io/adk-docs/tools/built-in-tools/#use-built-in-tools-with-other-tools. Just do combination of customized tool and built-in tools with AgentTool
This issue has been resolved. Built-in tools can now co-exist with FunctionDeclaration tools in the same agent.
What was fixed:
- Added
bypass_multi_tools_limitparameter to GoogleSearchTool and VertexAiSearchTool - Commit: 9a6b850
Solutions:
- Set
bypass_multi_tools_limit=Truewhen initializing built-in tools, OR - Wrap built-in tools in a dedicated agent using AgentTool
Resources:
- Sample code: contributing/samples/built_in_multi_tools
- Documentation: https://google.github.io/adk-docs/tools/built-in-tools/#use-built-in-tools-with-other-tools
Thanks to everyone who contributed workarounds and helped test solutions. Closing this as resolved. If you're still experiencing issues, please open a new issue with details.
@Jacksunwei this seems like clever workaround to me, not a fix. A fix would be adding an array of
...
tools=[my_tool, google_search]
and for it to both work with the same agent model. That's my 0.02.
@Jacksunwei the solution you mentioned does not work when custom functions are provided alongside built-in tools via a Toolset. I am using a custom toolset implementation which inherits from BaseToolset as this is - afaik - the only way to perform async initialisation actions required for the tools (not show in this example - but required for my actual use-case).
Am I missing something here, or is there another way to achieve the async initialisation I require and use custom and built-in tools together in a single agent? Seems to me that this issue should be reopened unless I've missed something.
MRE based on the example for builtin tools use.
import random
import typing as _t
from google.adk import Agent
from google.adk.agents.llm_agent import ToolUnion
from google.adk.agents.readonly_context import ReadonlyContext
from google.adk.tools import BaseTool, FunctionTool, ToolContext
from google.adk.tools.base_toolset import BaseToolset
from google.adk.tools.google_search_tool import GoogleSearchTool
def roll_die(sides: int, tool_context: ToolContext) -> int:
"""Roll a die and return the rolled result.
Args:
sides: The integer number of sides the die has.
Returns:
An integer of the result of rolling the die.
"""
result = random.randint(1, sides)
if "rolls" not in tool_context.state:
tool_context.state["rolls"] = []
tool_context.state["rolls"] = tool_context.state["rolls"] + [result]
return result
class MyToolset(BaseToolset):
def __init__(self, *args: _t.Any, tools: list[ToolUnion], **kwargs: _t.Any) -> None:
super().__init__(*args, **kwargs)
self._tools = tools
async def get_tools(
self,
readonly_context: _t.Optional[ReadonlyContext] = None,
) -> list[BaseTool]:
"""Returns the list of tools after ensuring DI container is started up."""
return self._tools
root_agent = Agent(
model="gemini-2.5-flash",
name="hello_world_agent",
description="A hello world agent with multiple tools.",
instruction="""
You are a helpful assistant which can help user to roll dice and search for information.
- Use `roll_die` tool to roll dice.
- Use `google_search` to search for general information.
""",
tools=[
MyToolset(
tools=[
# roll_die,
FunctionTool(func=roll_die),
GoogleSearchTool(bypass_multi_tools_limit=True),
],
)
],
)
Running this with google-adk v1.18.0 and google-genai v1.53.0 results in the same old multiple tools use error message.
...
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Multiple tools are supported only when they are all search tools.', 'status': 'INVALID_ARGUMENT'}}
My colleague @glaforge told me this is a MODEL limitation, not an ADK limitation. is this correct?