Repository navigation
fix(openai): keep the keys beside "result" in a Responses tool output - #7837
Open
adityasingh2400 wants to merge 1 commit into
Open
adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
_serialize_json_value unwrapped any tool dict with a non-None "result" key
and sent only that value, so a tool returning
{"result": ..., "contracts": [...], "next_page_token": ...} lost
everything but the result text. Unwrap only ADK's own {"result": value}
wrapper for non-dict returns and send other dicts whole, as AnthropicLlm
already does.
Fixes google#7836
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):
Problem:
_serialize_json_valueunwrapped any tool dict with a non-None"result"key and sent only that value as thefunction_call_output. A tool returning{"result": "found 2 contracts", "contracts": [...], "next_page_token": "abc"}therefore reached the model as justfound 2 contracts, and the rest of the data was silently lost.Solution:
Unwrap only when the keys are exactly
{"result"}, which is ADK's wrapper for a non-dict tool return. Any other dict is JSON-encoded whole. This is the same ruleAnthropicLlmuses since #7073. Bare{"result": value}returns, MCPcontentlists and plain strings are serialized as before.Testing Plan
Unit Tests:
Added to
tests/unittests/integrations/openai/test_openai_responses_llm.py:test_function_response_unwraps_adk_result_wrapper:{"result": "sunny"}→sunny, and{"result": [1, 2]}→[1, 2]. This behavior is unchanged.test_function_response_keeps_keys_beside_result: the full dict round-trips.pre-commit runpasses on the changed files, andmypyreports no issues in_openai_responses_llm.py.Manual End-to-End (E2E) Tests:
I ran a
RunnerwithLlmAgent(model=OpenAIResponsesLlm(model="gpt-5"), tools=[search_contracts]). The function tool returns the dict above. Only the client'sresponses.createis replaced: it records each request, asks forsearch_contractsfirst and answers second. The output below is thefunction_call_outputin the second request:Checklist
Additional context
None.