File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -506,7 +506,11 @@ def _part_to_message_block(
506506 # We serialize to str here
507507 # SDK ref: anthropic.types.tool_result_block_param
508508 # https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/types/tool_result_block_param.py
509- elif "result" in response_data and response_data ["result" ] is not None :
509+ # Exactly {"result": value} is ADK's wrapper for a non-dict tool return.
510+ elif (
511+ response_data .keys () == {"result" }
512+ and response_data ["result" ] is not None
513+ ):
510514 result = response_data ["result" ]
511515 if isinstance (result , (dict , list )):
512516 content = json .dumps (result )
Original file line number Diff line number Diff line change @@ -1288,6 +1288,28 @@ def test_part_to_message_block_nested_dict_result():
12881288 assert parsed ["results" ][0 ]["tags" ] == ["a" , "b" ]
12891289
12901290
1291+ def test_part_to_message_block_keys_beside_result_are_kept ():
1292+ """A tool's own dict travels whole even when one of its keys is 'result'."""
1293+ response_part = types .Part .from_function_response (
1294+ name = "run_code" ,
1295+ response = {
1296+ "result" : "ok" ,
1297+ "files" : ["report.csv" ],
1298+ "stdout" : "wrote report.csv" ,
1299+ },
1300+ )
1301+ response_part .function_response .id = "test_id"
1302+
1303+ result = part_to_message_block (response_part )
1304+
1305+ parsed = json .loads (result ["content" ])
1306+ assert parsed == {
1307+ "result" : "ok" ,
1308+ "files" : ["report.csv" ],
1309+ "stdout" : "wrote report.csv" ,
1310+ }
1311+
1312+
12911313# --- Tests for arbitrary dict fallback (e.g. SkillToolset load_skill) ---
12921314
12931315
You can’t perform that action at this time.
0 commit comments