@@ -280,11 +280,9 @@ def test_function_response_dict(self):
280280 assert result ['type' ] == 'function_result'
281281 assert result ['call_id' ] == 'call_123'
282282 assert result ['name' ] == 'get_weather'
283- # Dict should be JSON serialized
284- assert json .loads (result ['result' ]) == {
285- 'temperature' : 20 ,
286- 'condition' : 'sunny' ,
287- }
283+ # Dict should be passed through directly (not JSON-serialized).
284+ assert result ['result' ] == {'temperature' : 20 , 'condition' : 'sunny' }
285+ assert isinstance (result ['result' ], dict )
288286
289287 def test_function_response_simple (self ):
290288 """Test converting a function response Part with simple response."""
@@ -299,8 +297,37 @@ def test_function_response_simple(self):
299297 assert result ['type' ] == 'function_result'
300298 assert result ['call_id' ] == 'call_123'
301299 assert result ['name' ] == 'check_weather'
302- # Dict should be JSON serialized
303- assert json .loads (result ['result' ]) == {'message' : 'Weather is sunny' }
300+ # Dict should be passed through directly (not JSON-serialized).
301+ assert result ['result' ] == {'message' : 'Weather is sunny' }
302+
303+ def test_function_response_dict_not_double_serialized (self ):
304+ """Regression test: avoid double-serializing bash tool outputs.
305+
306+ Bash tool responses contain JSON structures (stdout/stderr). When these
307+ dict responses were json.dumps()'d before being sent to the Interactions
308+ API, the API's own serialization would escape the already-escaped content,
309+ producing unreadable output like:
310+ {"result":"\\ \" {\\ \\ \\ \" error\\ \\ \\ \" :\\ \\ \\ \" ...\\ \\ \\ \" }\\ \" "
311+ """
312+ bash_response = {
313+ 'stdout' : '{"name": "test", "version": "1.0"}\n ' ,
314+ 'stderr' : '' ,
315+ }
316+ part = types .Part (
317+ function_response = types .FunctionResponse (
318+ id = 'call_bash' ,
319+ name = 'bash' ,
320+ response = bash_response ,
321+ )
322+ )
323+ result = interactions_utils .convert_part_to_interaction_content (part )
324+ # The result value must be the dict itself, NOT a JSON string.
325+ assert isinstance (result ['result' ], dict )
326+ assert result ['result' ] == bash_response
327+ # Verify there's no double-escaping: if result were a JSON string,
328+ # serializing it again would add backslashes before the internal quotes.
329+ wire_json = json .dumps (result )
330+ assert '\\ \\ ' not in wire_json
304331
305332 def test_inline_data_image (self ):
306333 """Test converting an inline image Part."""
0 commit comments