Skip to content

Commit 0534122

Browse files
CopilotCopilot
andcommitted
Address review: call_id fallback for non-streaming path and test coverage (#4814)
- Apply defensive call_id fallback (getattr with id/call_id/empty) to non-streaming mcp_call path for consistency with streaming path - Add raw_representation assertion to call_id fallback test - Add test for empty-string fallback when neither id nor call_id exist Co-authored-by: Copilot <[email protected]>
1 parent 45f5b61 commit 0534122

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎python/packages/core/agent_framework/openai/_responses_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ def _parse_response_from_openai(
15421542
)
15431543
)
15441544
case "mcp_call":
1545-
call_id = item.id
1545+
call_id = getattr(item, "id", None) or getattr(item, "call_id", None) or ""
15461546
contents.append(
15471547
Content.from_mcp_server_tool_call(
15481548
call_id=call_id,

‎python/packages/core/tests/openai/test_openai_responses_client.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,33 @@ def test_parse_chunk_from_openai_with_mcp_output_item_done_call_id_fallback() ->
13031303
assert result_content.call_id == "mcp_fallback_123"
13041304
assert result_content.output is not None
13051305
assert result_content.output[0].text == "fallback result"
1306+
assert result_content.raw_representation is mock_item
1307+
1308+
1309+
def test_parse_chunk_from_openai_with_mcp_output_item_done_no_id_fallback() -> None:
1310+
"""Test that response.output_item.done for mcp_call falls back to empty string when neither id nor call_id exist."""
1311+
client = OpenAIResponsesClient(model_id="test-model", api_key="test-key")
1312+
1313+
mock_event = MagicMock()
1314+
mock_event.type = "response.output_item.done"
1315+
1316+
mock_item = MagicMock(spec=[])
1317+
mock_item.type = "mcp_call"
1318+
mock_item.output = "some result"
1319+
mock_event.item = mock_item
1320+
1321+
function_call_ids: dict[int, tuple[str, str]] = {}
1322+
1323+
update = client._parse_chunk_from_openai(mock_event, options={}, function_call_ids=function_call_ids)
1324+
1325+
assert len(update.contents) == 1
1326+
result_content = update.contents[0]
1327+
1328+
assert result_content.type == "mcp_server_tool_result"
1329+
assert result_content.call_id == ""
1330+
assert result_content.output is not None
1331+
assert result_content.output[0].text == "some result"
1332+
assert result_content.raw_representation is mock_item
13061333

13071334

13081335
def test_prepare_message_for_openai_with_function_approval_response() -> None:

0 commit comments

Comments
 (0)