Skip to content

Python: Add search tool content for OpenAI responses#5302

Open
eavanvalkenburg wants to merge 2 commits intomicrosoft:mainfrom
eavanvalkenburg:copilot/search-tool-content
Open

Python: Add search tool content for OpenAI responses#5302
eavanvalkenburg wants to merge 2 commits intomicrosoft:mainfrom
eavanvalkenburg:copilot/search-tool-content

Conversation

@eavanvalkenburg
Copy link
Copy Markdown
Member

Motivation and Context

OpenAI Responses web and file search built-in tools currently show up in raw provider output, but the Python OpenAI chat client drops them from the framework content model. This change preserves those built-in tool calls/results so downstream surfaces can observe them the same way they already can for code interpreter, shell, image generation, and MCP tool activity.

Description

  • add search_tool_call and search_tool_result content types in core
  • map OpenAI non-streaming web_search_call and file_search_call output items into those content types
  • map OpenAI streaming response.output_item.added / response.output_item.done search items into those content types and explicitly ignore search progress events instead of leaving them as unparsed noise
  • forward seen_reasoning_delta_item_ids through both OpenAI streaming paths so reasoning done events are suppressed after deltas consistently
  • add unit tests covering the new search parsing and the streamed reasoning-dedup paths

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 09:38
@github-actions github-actions bot changed the title Add search tool content for OpenAI responses Python: Add search tool content for OpenAI responses Apr 16, 2026
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 16, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _types.py10928792%58, 67–68, 122, 127, 146, 148, 152, 156, 158, 160, 162, 180, 184, 210, 232, 237, 242, 246, 276, 689–690, 849–850, 1285, 1357, 1392, 1412, 1422, 1474, 1606–1608, 1790, 1893–1898, 1923, 2011, 2019–2021, 2026, 2117, 2129, 2152, 2407, 2431, 2526, 2775, 2982, 3055, 3066, 3068–3072, 3074, 3077–3085, 3095, 3165, 3300, 3305, 3310, 3315, 3319, 3403–3405, 3434, 3511–3515
packages/openai/agent_framework_openai
   _chat_client.py91412186%522–525, 529–530, 536–537, 572–578, 599, 607, 630, 748, 847, 906, 908, 910, 912, 978, 992, 1072, 1082, 1087, 1130, 1246, 1427, 1432, 1436–1438, 1442–1443, 1509, 1538, 1544, 1554, 1560, 1565, 1571, 1576–1577, 1596, 1686, 1708–1709, 1724–1725, 1743–1744, 1787, 1953, 1991–1992, 2008, 2010, 2089–2097, 2127, 2234, 2269, 2284, 2304–2314, 2327, 2338–2342, 2356, 2370–2381, 2390, 2422–2425, 2435–2436, 2447–2449, 2463–2465, 2475–2476, 2482, 2497
TOTAL27730319988% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5615 20 💤 0 ❌ 0 🔥 1m 31s ⏱️

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Python OpenAI Responses chat client and the core content model to preserve OpenAI built-in web/file search tool activity (calls/results) in the framework’s unified Content representation, including streaming support and reasoning-done de-duplication.

Changes:

  • Add new unified content types: search_tool_call and search_tool_result in core.
  • Parse OpenAI non-streaming web_search_call / file_search_call output items into those new content types.
  • Parse OpenAI streaming search output items (response.output_item.added / response.output_item.done), explicitly ignore search progress events, and forward seen_reasoning_delta_item_ids consistently across both streaming paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
python/packages/openai/agent_framework_openai/_chat_client.py Maps Responses API search output items into unified Content objects; ignores search progress events; forwards reasoning delta tracking through both streaming paths.
python/packages/core/agent_framework/_types.py Extends ContentType and adds Content.from_search_tool_call() / Content.from_search_tool_result() constructors; updates argument parsing docstring.
python/packages/openai/tests/openai/test_openai_chat_client.py Adds unit tests for non-streaming + streaming search parsing and for reasoning done suppression after deltas across both streaming implementations.
Comments suppressed due to low confidence (1)

python/packages/core/agent_framework/_types.py:1543

  • Content.parse_arguments() docstring states it raises ContentError when the content type doesn't support arguments, but the implementation doesn't check self.type and will never raise that error. Please either add an explicit type guard (e.g., allow only function_call/mcp_server_tool_call/search_tool_call) or update the docstring to reflect the actual behavior.
    def parse_arguments(self) -> dict[str, Any | None] | None:
        """Parse arguments from function_call, mcp_server_tool_call, or search_tool_call content.

        If arguments cannot be parsed as JSON or the result is not a dict,
        they are returned as a dictionary with a single key "raw".

        Returns:
            Parsed arguments as a dictionary, or None if no arguments.

        Raises:
            ContentError: If the content type doesn't support arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants