Skip to content

Efficiency Bug

⚠️ OpenAI Agents SDK Is Wasting Your Resources Here's Why

If you're using the stop_on_first_tool behavior in the OpenAI Agents SDK with parallel tool calls enabled... there's a silent inefficiency you need to know.

Let me break it down:


πŸ” What Actually Happens Under the Hood

When you do this:

Python
1
2
3
4
5
model_settings = ModelSettings(
    tool_choice="auto",
    parallel_tool_calls=True,
),
tool_use_behavior="stop_on_first_tool"

And the LLM selects multiple tools like:

Python
tool_calls = [test_tool_one, test_tool_two]

Here’s what the agent actually does:

  1. The LLM chooses both tools in a single step
  2. The SDK uses asyncio.gather() to run all tool calls in parallel
  3. All tools execute to completion even if test_tool_two is expensive or unnecessary
  4. Then it simply discards every result except tool_results[0]
  5. Your system never even uses the output of the other tools

πŸ—‘οΈ That Means: Tool Results Are Wasted

  • β›½ API tokens spent for unused calls
  • πŸ•’ Time lost on long-running or blocking tools
  • ⚠️ Side effects triggered even when their results are thrown away
  • πŸ’Έ You're billed, they’re ignored

If you're calling external APIs or hitting databases, this can get really expensive.


❓ Why Does This Happen?

It’s a design trade-off.

The current SDK chooses determinism over efficiency. It guarantees predictable behavior by always using tool_results[0], regardless of execution order or timing.

But it does not cancel remaining tasks once the first completes. It does not use asyncio.wait(..., return_when=FIRST_COMPLETED).

This means: you pay for all tools, use only one.


βœ… What Should You Do?

If you're using stop_on_first_tool, do one of the following:

  1. Only register one tool per step don't give it choices
  2. Avoid parallel_tool_calls=True with stop_on_first_tool behavior
  3. Write a custom async executor that uses FIRST_COMPLETED and cancels the rest

βš™οΈ What's Missing in the SDK?

The SDK should ideally support:

  • Efficient first-response wins behavior
  • Tool cancellation on-the-fly
  • Configurable execution modes for budget-conscious agents

πŸ” Until then, it’s up to us to optimize tool usage manually.

πŸ’¬ If you’re building agents with expensive tools, keep this in mind or you might be burning tokens and time for nothing.

To see a practical example of this: https://github.com/DanielHashmi/AgenticAIProjects/blob/main/openai_agents_sdk_parallel_tool_calls.py

If you found this helpful ⭐ this repo! Keep Coding πŸ’–