C.W.K.
Stream
Lesson 05 of 07 · published

Parallel Function Calling

~22 min · parallel-calls, concurrency

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Models can call multiple functions in a single turn. This is the default behavior — the model may determine that answering requires data from several tools simultaneously.

Note: gpt-4.1-nano may return duplicate tool calls — disable parallel calling when using it. In the Responses API, parallel tool calling is the default and there's no parameter to disable it.

The model batches independent calls; you should run them parallel

When the model returns three tool_calls in a single response, it's saying 'these three calls are independent and you can run them in any order'. Sequential execution wastes 2/3 of the wall time for no reason. asyncio.gather (or threading for sync handlers) returns all three results in the time of the slowest one.

If your tools have ordering requirements (call B depends on A's result), set parallel_tool_calls=False. The model will then emit one tool_call per turn, you handle it, send the result back, the model emits the next. Slower but explicit.

Code

Handling multiple tool_calls in one turn·python
import asyncio

# The model may call both get_weather and search_news in one turn
# Execute them in parallel for speed:

async def execute_tools(tool_calls):
    tasks = []
    for tc in tool_calls:
        func = TOOLS_MAP[tc.name]
        args = json.loads(tc.arguments)
        if asyncio.iscoroutinefunction(func):
            tasks.append(asyncio.wait_for(func(**args), timeout=30.0))
        else:
            loop = asyncio.get_event_loop()
            tasks.append(loop.run_in_executor(None, lambda f=func, a=args: f(**a)))
    return await asyncio.gather(*tasks, return_exceptions=True)

# To disable parallel calling (Chat Completions only):
completion = client.chat.completions.create(
    model="gpt-5.4",
    tools=tools,
    messages=messages,
    parallel_tool_calls=False,  # enforce serial, one tool at a time
)

External links

Exercise

Prompt the model to fetch weather for 3 cities. Verify it returns 3 tool_calls in one response. Run them with asyncio.gather. Time the parallel run vs sequential — record the speedup.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.