fix(agent_tool): wrap input_schema payload in ReAct prompt and propagate tool_choice to LiteLLM
Summary
Fixes two issues that prevent Claude-family models from entering the ReAct tool-calling loop when used via LiteLLM inside a nested AgentTool:
AgentToolwithinput_schema— the serialized JSON payload sent as the first message causes Claude to interpret the request as already complete and respond directly without calling any tools.tool_choicenot propagated —llm_request.config.tool_config.function_calling_config.modewas not forwarded to LiteLLM'scompletion_args, so callers could not enforce tool use at the request level.
Changes
src/google/adk/tools/agent_tool.py
Wrap the serialized input_schema JSON in a natural-language instruction that explicitly asks the inner agent to use its available tools before producing a response. This keeps Claude in ReAct mode regardless of the message content format.
src/google/adk/models/lite_llm.py
Read llm_request.config.tool_config.function_calling_config.mode and map it to LiteLLM's tool_choice parameter:
ANY→"required"NONE→"none"AUTO→ provider default (unchanged, key omitted fromcompletion_args)
_get_completion_inputs now returns a 5-tuple (messages, tools, response_format, generation_params, tool_choice).
Unit Tests Added
tests/unittests/tools/test_agent_tool.py
test_run_async_no_input_schema_passes_request_unchanged: withoutinput_schema, the content passed to the inner runner isargs['request']verbatim.test_run_async_with_input_schema_wraps_in_natural_language: withinput_schema, the text begins with"Process the following structured request", contains"Request:\n"followed by the JSON payload, and is not a bare JSON blob.test_run_async_with_input_schema_text_not_raw_json: asserts the text does not start with{.
tests/unittests/models/test_litellm.py
test_get_completion_inputs_tool_choice_none_without_tool_config:tool_choiceisNonewith notool_config.test_get_completion_inputs_tool_choice_required_for_any_mode: returns"required"forANYmode.test_get_completion_inputs_tool_choice_none_for_none_mode: returns"none"forNONEmode.test_get_completion_inputs_tool_choice_none_for_auto_mode: returnsNoneforAUTOmode.test_generate_content_async_propagates_tool_choice_required:acompletionreceivestool_choice="required"forANY.test_generate_content_async_propagates_tool_choice_none_mode:acompletionreceivestool_choice="none"forNONE.test_generate_content_async_omits_tool_choice_for_auto_mode:tool_choicekey absent fromcompletion_argsforAUTO.test_generate_content_async_omits_tool_choice_without_tool_config:tool_choicekey absent when notool_config.
Also updated all existing _get_completion_inputs call sites (10 occurrences) to unpack the new 5-tuple.
Pytest Results
tests/unittests/tools/test_agent_tool.py + tests/unittests/models/test_litellm.py
1 failed (pre-existing: test_custom_schema[GOOGLE_AI] — unrelated to this PR),
302 passed, 1 skipped in 2.98s
New tests: 11 passed (3 agent_tool + 8 litellm)
The 1 pre-existing failure (test_custom_schema[GOOGLE_AI]) is a pydantic.ValidationError that reproduces on the base branch before any of these changes and is unrelated to this fix.
Related
- Fixes #5926
- Addresses #773 (expose tool_choice to callers via FunctionCallingConfig)
- Related #1063 (fixed FunctionDeclaration description in v1.20, different issue)
Response from ADK Triaging Agent
Hello @ecanlar, thank you for creating this PR!
We appreciate your contribution to fixing the LiteLLM/Claude AgentTool issue. To help our reviewers process this pull request more efficiently, please ensure it complies with our contribution guidelines.
Currently, the following items are missing:
- Unit Tests: The PR modifies behavior in
lite_llm.pyandagent_tool.py, but does not add or update any unit tests (e.g., undertests/unittests/). Please add unit tests covering the new tool wrapping andtool_choicebehavior. - Pytest Results Summary: Please run the tests and include a summary of the passed
pytestortoxresults in the PR description. - Logs/Screenshots: Please provide console logs or screenshots demonstrating that the inner agent successfully enters the ReAct loop and calls tools after applying the fix.
Providing this information helps ensure high code quality, prevents future regressions, and makes the review process smoother. Thank you!
Good catch — confirmed the guard was not in place. tool_choice and tools were derived from two independent config fields (config.tool_config and config.tools) with no cross-check, so a caller setting mode=ANY with no function_declarations would reach acompletion() with tools=None, tool_choice="required" — exactly the combination LiteLLM rejects.
Fixed in the latest commit:
_get_completion_inputs: coercetool_choicetoNonewhentoolsis falsy before returning.generate_content_async: nulltool_choicealongsidetoolsinside the"functions"additional-arg branch.
Two new tests cover both paths; 10 tool_choice tests passing.
Hi @ecanlar , Thank you for your contribution! We appreciate you taking the time to submit this pull request.
/adk-pr-analyze
Hi @ecanlar , Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.
Hi @GWeale , can you please review this.
Hi @ecanlar , can you please fix formatting errors.
i fixed the formatting erros. @rohityan