Repository navigation
fix(models): read Llama's "parameters" key in inline LiteLlm tool calls - #8382
Open
Yasser-Ameur wants to merge 1 commit into
Open
Yasser-Ameur wants to merge 1 commit into
Yasser-Ameur wants to merge 1 commit into
Conversation
Llama 3.x JSON tool calling answers with {"name": ..., "parameters": {...}},
optionally after <|python_tag|>. When LiteLLM hands that text back in the
message content, LiteLlm left it as text and the tool never ran.
The inline tool call fallback in _build_tool_call_from_json_dict read only
the "arguments" key and returned None when it was missing.
It now falls back to "parameters" when the object has no "arguments" key and
no "description" key. A tool definition also has "parameters" and a
"description", so it stays text. JSON without either key is treated as
before. An object with "name" and "parameters" and no "description" is now
read as a call, the same way an object with "name" and "arguments" already
is.
5 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Describe the Bug
When LiteLLM returns a Llama 3.x JSON tool call as message text,
LiteLlmdoes not turn it into a function call. Llama 3.x documents the form{"name": ..., "parameters": {...}}, optionally after<|python_tag|>, which ADK already strips as a call prefix._build_tool_call_from_json_dictinsrc/google/adk/models/lite_llm.pyreads onlyarguments, so the text is returned as model text and the tool never runs.Steps to Reproduce (offline, no model needed)
Expected Behavior
A function call
get_weatherwith{"city": "Paris"}, as for the same object written witharguments.Observed Behavior
Base SHA 03725e8:
With the fix (5b3dd94):
The leftover
<|python_tag|>text part is existing behaviour for that prefix.Environment Details
Python 3.14.7, google-adk at 03725e8 (editable install), litellm and openai installed per
constraints-3.14.txt, Windows 11.Model Information
Llama 3.x (3.1 and 3.3 JSON tool calling) through LiteLLM. No live model run was done. Which provider routes (Ollama, vLLM, others via LiteLLM) actually return this form as text, instead of translating it to
tool_calls, is not confirmed. The format comes from Meta's Llama 3.1 and 3.3 prompt format docs and Ollama's Llama 3.1 template; vLLM's llama3_json parser (v0.10.0) acceptsparameterswhenargumentsis absent.Solution:
In
_build_tool_call_from_json_dict, readparameterswhen the object has noargumentskey and nodescriptionkey.argumentsstill wins whenever the key is present (including null, which stays text as on main). A tool definition also carriesparameters, and itsdescriptionkeeps it as text.parametersas a dict or JSON string follows the same pathargumentsdoes. One change covers the non-streaming and streaming paths, which share_parse_tool_calls_from_text.One trade-off to be aware of: an answer that is an object with
nameandparametersand nodescriptionis now read as a call, the same way an object withnameandargumentsalready is. The fallback is not gated on declared tools on main either.parametersgiven as a list or a non-JSON string was text before and now yieldsMALFORMED_FUNCTION_CALL, as theargumentsform does on main.Testing Plan
Unit Tests:
Three tests (9 cases) in
tests/unittests/models/test_litellm.py:parametersbare and after<|python_tag|>, as a dict and as a JSON string;argumentspreferred when both exist; non-tool JSON stays text, including a tool definition withdescriptionandparameters.On the base source the new tests give
4 failed, 5 passed, 890 deselected in 6.09s; with the fix9 passed, 890 deselected in 5.08s. The whole file:899 passed, 5 warnings in 8.60s. pyink, isort and ruff are clean and mypy reports no issues onlite_llm.py. The full unit suite was not run locally.Manual End-to-End (E2E) Tests:
None against a live model. The offline snippet above is the check, with its output on the base commit and on this branch.
Checklist