|
24 | 24 | MCPListToolsItem, |
25 | 25 | MessageOutputItem, |
26 | 26 | ReasoningItem, |
| 27 | + ToolApprovalItem, |
27 | 28 | ToolCallItem, |
28 | 29 | ToolCallOutputItem, |
29 | 30 | ToolSearchCallItem, |
@@ -1015,3 +1016,57 @@ def test_removes_mixed_mcp_and_function_items() -> None: |
1015 | 1016 | assert len(filtered_data.input_history) == 2 |
1016 | 1017 | assert len(filtered_data.pre_handoff_items) == 1 |
1017 | 1018 | assert len(filtered_data.new_items) == 1 |
| 1019 | + |
| 1020 | + |
| 1021 | +def _get_hosted_tool_input_item(type_name: str) -> TResponseInputItem: |
| 1022 | + return cast(TResponseInputItem, {"id": "ht1", "type": type_name}) |
| 1023 | + |
| 1024 | + |
| 1025 | +def _get_tool_approval_run_item() -> ToolApprovalItem: |
| 1026 | + return ToolApprovalItem( |
| 1027 | + agent=fake_agent(), |
| 1028 | + raw_item={"type": "function_call", "call_id": "c1", "name": "fn", "arguments": "{}"}, |
| 1029 | + tool_name="fn", |
| 1030 | + ) |
| 1031 | + |
| 1032 | + |
| 1033 | +def test_removes_hosted_tool_types_from_input_history() -> None: |
| 1034 | + """Hosted tool types in raw input history should be removed by remove_all_tools.""" |
| 1035 | + hosted_types = [ |
| 1036 | + "code_interpreter_call", |
| 1037 | + "image_generation_call", |
| 1038 | + "local_shell_call", |
| 1039 | + "local_shell_call_output", |
| 1040 | + "shell_call", |
| 1041 | + "shell_call_output", |
| 1042 | + "apply_patch_call", |
| 1043 | + "apply_patch_call_output", |
| 1044 | + ] |
| 1045 | + input_items: list[TResponseInputItem] = [_get_message_input_item("Hello")] |
| 1046 | + for t in hosted_types: |
| 1047 | + input_items.append(_get_hosted_tool_input_item(t)) |
| 1048 | + input_items.append(_get_message_input_item("World")) |
| 1049 | + |
| 1050 | + handoff_input_data = handoff_data(input_history=tuple(input_items)) |
| 1051 | + filtered_data = remove_all_tools(handoff_input_data) |
| 1052 | + assert len(filtered_data.input_history) == 2 |
| 1053 | + for item in filtered_data.input_history: |
| 1054 | + assert not isinstance(item, str) |
| 1055 | + assert item.get("type") not in set(hosted_types) |
| 1056 | + |
| 1057 | + |
| 1058 | +def test_removes_tool_approval_from_new_items() -> None: |
| 1059 | + """ToolApprovalItem should be removed from new_items and pre_handoff_items.""" |
| 1060 | + handoff_input_data = handoff_data( |
| 1061 | + pre_handoff_items=( |
| 1062 | + _get_tool_approval_run_item(), |
| 1063 | + _get_message_output_run_item("kept"), |
| 1064 | + ), |
| 1065 | + new_items=( |
| 1066 | + _get_tool_approval_run_item(), |
| 1067 | + _get_message_output_run_item("also kept"), |
| 1068 | + ), |
| 1069 | + ) |
| 1070 | + filtered_data = remove_all_tools(handoff_input_data) |
| 1071 | + assert len(filtered_data.pre_handoff_items) == 1 |
| 1072 | + assert len(filtered_data.new_items) == 1 |
0 commit comments