Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/google/adk/integrations/openai/_openai_responses_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def _serialize_json_value(value: object) -> str:
return '\n'.join(content_items)
if isinstance(content, str) and content:
return content
if 'result' in value and value['result'] is not None:
# Exactly {'result': value} is ADK's wrapper for a non-dict tool return. A
# tool's own dict that merely has a 'result' key is sent whole.
if value.keys() == {'result'} and value['result'] is not None:
result = value['result']
if isinstance(result, str):
return result
Expand Down
32 changes: 32 additions & 0 deletions tests/unittests/integrations/openai/test_openai_responses_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations

import json
import logging
from unittest import mock

Expand Down Expand Up @@ -369,6 +370,37 @@ def test_content_mapping_sanitizes_function_call_ids_per_request():
assert items[3]['call_id'] == 'call_adk_fallback_2'


def _function_output(response: dict[str, object]) -> str:
content = types.Content(
role='tool',
parts=[
types.Part(
function_response=types.FunctionResponse(
id='call_123', name='tool', response=response
)
)
],
)
return _content_to_response_input_items(content)[0]['output']


def test_function_response_unwraps_adk_result_wrapper():
"""Exactly {"result": value} is ADK's wrapper for a non-dict tool return."""
assert _function_output({'result': 'sunny'}) == 'sunny'
assert _function_output({'result': [1, 2]}) == '[1, 2]'


def test_function_response_keeps_keys_beside_result():
"""A tool dict that merely has a "result" key is sent whole."""
response = {
'result': 'found 2 contracts',
'contracts': ['NDA-12', 'MSA-7'],
'next_page_token': 'abc',
}

assert json.loads(_function_output(response)) == response


def test_function_response_serializes_mcp_content_as_text():
"""MCP-style text content is flattened for function_call_output."""
content = types.Content(
Expand Down
Loading