Repository navigation
fix(openai): don't run tool calls with truncated or malformed arguments - #8192
Open
yibol9768-alt wants to merge 1 commit into
Open
yibol9768-alt wants to merge 1 commit into
yibol9768-alt wants to merge 1 commit into
Conversation
Signed-off-by: Yibo Liu <yibol9768@gmail.com>
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):
reasoning/reasoning_content) #8191 (point 4 of the proposal there)2. Or, if no issue exists, describe the change:
Problem:
In
OpenAILlm(src/google/adk/integrations/openai/_openai_llm.py), tool-call arguments that are not valid JSON, or that parse to something other than a JSON object, becomeargs={}and the call is returned as a normal success, in both the non-streaming path (_tool_call_parts) and the streaming path. This includes a call cut off bymax_tokens(finish_reason="length"). The flow then runs the tool with no arguments, so a tool whose parameters are all optional runs with its defaults.Solution:
Same policy as the other adapters (#7803 for LiteLlm, #7686 for Apigee, #7558 for Claude):
finish_reason="length") returnerror_code=MAX_TOKENSand no function calls;error_code=MALFORMED_FUNCTION_CALL(soReflectAndRetryModelPlugincan retry) and no function calls;{}for no-argument tools, and text content is kept.Raw arguments are not logged, only the tool name and length.
Testing Plan
Unit Tests:
New tests in
tests/unittests/integrations/openai/test_openai_llm.pycover truncated and malformed arguments ([],null,"x", invalid JSON) in both paths, a batch with text plus a truncated call, and valid / empty arguments still succeeding. 11 of them fail onmain; with this changepytest tests/unittests/integrations/openai/gives 306 passed. pyink, isort, ruff and mypy pass on the changed file.Manual End-to-End (E2E) Tests:
vllm serve Qwen/Qwen3-1.7B --enable-auto-tool-choice --tool-call-parser hermeson a local RTX 5090,OpenAILlm(base_url=...), awrite_note(text, path)tool,max_output_tokens=30, so the call is cut off mid-arguments (finish_reason="length"):mainfunction_calls=[('write_note', {})],error_code=Nonefunction_calls=[],error_code=MAX_TOKENStool_calls; same on bothChecklist
Additional context
This is independent of the reasoning changes discussed in #8191 and touches only the tool-call parsing in
_openai_llm.py.