Skip to content

Python: Add search tool content for OpenAI responses - #5302

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft:mainfrom
eavanvalkenburg:copilot/search-tool-content
Apr 20, 2026
Merged

Python: Add search tool content for OpenAI responses#5302
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits into
microsoft: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.

Copilot AI review requested due to automatic review settings April 16, 2026 09:38
@moonbox3 Evan Mattson (moonbox3) added the python Usage: [Issues, PRs], Target: Python label Apr 16, 2026
@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

Evan Mattson (moonbox3) commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _types.py10968792%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, 2017, 2025–2027, 2032, 2123, 2135, 2158, 2413, 2437, 2536, 2790, 2999, 3072, 3083, 3085–3089, 3091, 3094–3102, 3112, 3182, 3317, 3322, 3327, 3332, 3336, 3420–3422, 3451, 3528–3532
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
TOTAL28372329888% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5665 30 💤 0 ❌ 0 🔥 1m 33s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
Merged via the queue into microsoft:main with commit 3e54a68 Apr 20, 2026
31 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the copilot/search-tool-content branch June 30, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants