Skip to content

web_search_preview tool call is not limited by max_turns option #783

Closed
@jihun-im-open

Description

@jihun-im-open

Please read this first

Yes

Describe the bug

max_turns of run_streamed() is ignored for web_search_preview tool

Debug information

  • Agents SDK version: v0.0.15
  • Python version: Python 3.11

Repro steps

https://gist.github.com/jihun-im-open/b1351fb44320f83d72d50ab9f98a50da

Expected behavior

MaxTurn Error should be raised

Activity

rm-openai

rm-openai commented on May 29, 2025

@rm-openai
Collaborator

All the web_search_preview calls happen on the server in one "turn", so this is expected. Is your goal to have at most 1 call to search?

jihun-im-open

jihun-im-open commented on May 30, 2025

@jihun-im-open
Author

I have encountered more than 6 sets of the following web_search_call events and those are regarded as a single turn:

  • response.web_search_call.in_progress
  • response.web_search_call.searching
  • response.web_search_call.completed

Here is full response stream:
https://gist.github.com/jihun-im-open/2468aca698f6dd34b226156008fa23bd

My intention is that it would be great if max_turns could limit the count of web_search_call.xxx events. This is because web_search_call could also fall into an almost infinite loop.

rm-openai

rm-openai commented on May 30, 2025

@rm-openai
Collaborator

Gotcha. We can't do this today, because max_turns is a local (SDK) param but the web searches happen in the API. An alternate approach is to set a max_tokens instead, which will force the model to use fewer tokens and hence fewer web searches?

jihun-im-open

jihun-im-open commented on Jun 2, 2025

@jihun-im-open
Author

Thanks @rm-openai ,

I see that we cannot control the API.

I solved this problem by counting ResponseWebSearchCallInProgressEvent events and canceling RunResultStreaming if a threshold is exceeded.

rm-openai

rm-openai commented on Jun 2, 2025

@rm-openai
Collaborator

Makes sense. I'll also look into adding more configurabilty to the API. thanks for the feedback.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jihun-im-open@rm-openai

        Issue actions

          web_search_preview tool call is not limited by max_turns option · Issue #783 · openai/openai-agents-python