Skip to content

feat(tools): add search_content_types and image_settings to WebSearchTool - #4704

Closed
fuchengwarrenzhu wants to merge 4 commits into
openai:mainfrom
fuchengwarrenzhu:add-web-search-content-types
Closed

fuchengwarrenzhu wants to merge 4 commits into
openai:mainfrom
fuchengwarrenzhu:add-web-search-content-types

Conversation

@fuchengwarrenzhu

@fuchengwarrenzhu fuchengwarrenzhu commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request adds the Responses API image-search controls to WebSearchTool:

  • search_content_types selects text and/or image results.
  • image_settings configures max_results and caption.
  • Selecting image results automatically requests web_search_call.results.

Both fields remain optional and are omitted when unset, preserving existing WebSearchTool behavior. WebSearchToolImageSettings is exported from agents, and the release contract now pins its import identity plus both optional TypedDict fields.

Per maintainer review and the repository's documentation release-timing policy, this feature PR does not update docs/tools.md; that release-timed documentation belongs in a separate docs-only PR.

Test plan

  • make format, make lint, and make typecheck pass.
  • Focused converter, export, and release-policy coverage: 68 passed.
  • make tests-serial: 77 passed, 4 skipped.
  • make tests: 9,193 passed and 55 skipped. The Codex workspace sandbox blocks 16 unrelated tests that bind local TCP or multiprocessing Unix sockets. One unrelated 0.2-second cancellation test timed out under xdist and passes alone. GitHub checks provide the unrestricted full-suite result.
  • Two independent final review rounds are clean on the pushed content.

Issue number

None.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

…Tool

The Responses API web_search tool accepts search_content_types
(["text", "image"]) and image_settings ({max_results, caption}) to
return image results alongside text. WebSearchTool had no way to set
them, so image search was unreachable through the SDK.

Both fields are optional and omitted from the tool payload when unset,
matching how external_web_access is passed through.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0118QL4rZytJhQHVCdYmkSRS

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f086a0b00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/tool.py Resolved
Comment thread docs/tools.md Resolved
Match the reviewed shape of openai#3474: when search_content_types includes
"image", add the web_search_call.results include so image results are
returned. Text-only configurations add no include.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0118QL4rZytJhQHVCdYmkSRS
@fuchengwarrenzhu

fuchengwarrenzhu commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Checked past PRs before opening this: #3474 (by @yuning-oai) proposed the same search_content_types support in May and was approved in principle — "We can merge at the timing of either public beta or GA" — then went stale while the feature was pre-release. Image search is now documented as available in the web search guide, so that timing condition is met.

This PR carries the same converter shape as #3474, including the web_search_call.results include when "image" is requested, and adds image_settings (max_results, caption), which the guide documents alongside it.

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The platform need is valid: the current OpenAI documentation defines search_content_types, image_settings, and web_search_call.results for image search.

Two repository-readiness changes are still required:

  • WebSearchToolImageSettings is part of the public WebSearchTool constructor annotation, so it must be exported from agents, included in the public export surface, and covered by an import regression test.
  • Please remove the new docs/tools.md claim from this feature PR. Repository policy requires documentation for behavior unavailable in the latest published SDK release to land in a separately timed docs-only PR (I will handle this doc PR).

The provider conversion and automatic web_search_call.results include otherwise look appropriately scoped.

Export the image settings type from the public package, preserve its
release contract, and defer unreleased documentation to the follow-up PR.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-04T18:55:26.487969Z 1a427db New commits
🔒 Security Review ✅ Completed 2026-09-04T18:58:22.013251Z 1a427db New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fuchengwarrenzhu

Copy link
Copy Markdown
Contributor Author

From codex:

Addressed in a86aa574.

  • Re-exported WebSearchToolImageSettings from agents, added it to agents.__all__, and added a direct-import identity regression.
  • Added release-contract coverage for the canonical import and both optional TypedDict fields.
  • Removed the unreleased docs/tools.md claim so the separately timed docs-only PR can land after the SDK behavior is released.

The updated fork workflow is awaiting maintainer approval. Ready for re-review once it runs.

@sylvesterkaczmarek sylvesterkaczmarek 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.

image_settings is accepted even when search_content_types is omitted or text-only. The converter still forwards image_settings, but it only requests web_search_call.results when "image" is selected, so the public constructor can produce a contradictory request. Could we require "image" whenever image_settings is set and add a regression?

…s set

image_settings configures results the request only asks for when
search_content_types includes "image"; the constructor now refuses the
pair without it, the same way ShellTool refuses an executor for a hosted
environment.
@fuchengwarrenzhu

Copy link
Copy Markdown
Contributor Author

Agreed, and fixed in 1a427db: WebSearchTool.__post_init__ now raises UserError when image_settings is set and search_content_types is omitted or lacks "image", mirroring how ShellTool refuses an executor for a hosted environment. test_web_search_tool_image_settings_require_image_results covers both invalid shapes; the existing converter test keeps the valid pair with its include. The image_settings docstring now says it requires image results.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a427db1f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/tool.py
Comment on lines +857 to +861
if self.image_settings is not None and (
self.search_content_types is None or "image" not in self.search_content_types
):
raise UserError(
'WebSearchTool image_settings requires search_content_types to include "image".'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the provider-only constructor validation

When a caller supplies image_settings without selecting "image", this guard raises during WebSearchTool construction even though it only duplicates Responses request grammar that the upstream provider can reject authoritatively; no SDK-owned state, side effect, or resource is at risk before that rejection. Remove this guard and its rejection test so the owning adapter/provider remains the source of truth for this provider-specific constraint.

AGENTS.md reference: AGENTS.md:L140-L140

Useful? React with 👍 / 👎.

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Thanks — this closes the contradictory request shape cleanly. Failing construction unless image is included in search_content_types is much safer than forwarding image_settings while omitting image results.

seratch added a commit that referenced this pull request Sep 7, 2026
Allow WebSearchTool to request image-only or mixed text/image results and
configure image settings through the existing Responses API tool payload.
Request raw image results automatically and export the public settings type.
Preserve existing constructor order and default behavior, with converter,
public import, and streaming/non-streaming HTTP request regression coverage.

Supersedes #4704.

Co-authored-by: Warren <[email protected]>
@seratch

seratch commented Sep 7, 2026

Copy link
Copy Markdown
Member

Thanks for working on this. The issue was resolved by #4898

@seratch seratch closed this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants