Assistant SDK: agent runs multiple searches

Good Morning,

i have a simple agent that makes use of the web-search. However: Sometimes the response takes 50s+ and the reason for it seems that the agent is doing a search over and over again.

Taking a look at the trace shows that the web-search in this case is multiple times, instead of just once.

I even put it into the prompt with “Use the WebSearchTool only ONCE.”

But it’s still sometimes running multiple times.

I am not sure if it’s a bug, or if I am maybe doing anything wrong here - Maybe someone has an idea?

1 Like

mind sharing the code for this?

You probably just spotted an interesting screenshot and want something from a developer for yourself.

Today you’re in luck, though. What’s showing is the tracing interface of the Agents API on the platform site.

Otherwise, “gimme your code if you want help” is not a great start to a problem likely coming from a model quality issue, given the “sometimes”.

i suppose i could have been clearer.

am aware of the traces ui & agents sdk

wanted to see how the original poster set up the agents since the prompt, max turns, temperature & tool choice param could be consequential here.

maybe try using “agents as tool” instead?

i have an implementation here where I also used web search & didn’t get the recursive loop: Agents Example: Multi-Agent via Tools/Handoff + Multiple Input & Output Guardrails + Streaming

1 Like