Closed
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rm-openai commentedon May 29, 2025
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 commentedon May 30, 2025
I have encountered more than 6 sets of the following web_search_call events and those are regarded as a single turn:
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 ofweb_search_call.xxx
events. This is becauseweb_search_call
could also fall into an almost infinite loop.rm-openai commentedon May 30, 2025
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 commentedon Jun 2, 2025
Thanks @rm-openai ,
I see that we cannot control the API.
I solved this problem by counting
ResponseWebSearchCallInProgressEvent
events and cancelingRunResultStreaming
if a threshold is exceeded.rm-openai commentedon Jun 2, 2025
Makes sense. I'll also look into adding more configurabilty to the API. thanks for the feedback.