Repository navigation
Conversation
The calls a model makes in one round now run concurrently, through one shared resolver (`resolveToolRound`) that every provider with its own tool loop uses: Anthropic, Gemini, Ollama, OpenAI, Open Responses, MLX and llama.cpp. This matches Foundation Models, which requires tools to be `Sendable` and may call a tool concurrently with itself or with other tools; a tool that isn't safe to run alongside others can serialize its own work. There's no setting to turn it on. Results keep the order the model gave the calls in. The delegate hears about the round and decides each call in order, as before, and a `.stop` still ends the round before any call runs. When a call throws, the others are cancelled and the first error is reported, as a throwing task group does; calls cancelled because of it aren't reported as failures. `parallel_tool_calls` is unchanged: it governs what a model may ask for, not how the calls run. Two 300 ms calls in one round take about 0.3 s instead of 0.6 s. Resolves huggingface#359. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B4WBsc1Jp8fGufe89MhQFB
gtokman
force-pushed
the
tools-concurrently
branch
from
October 29, 2026 13:38
cc8bd87 to
d69ecf9
Compare
mattt
reviewed
Oct 29, 2026
mattt
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, @gtokman. It's great to have seven copies of the tool loop down to one. Two things before we can merge this:
- When a call throws,
invokeToolCallawaitsdidFailToolCallbefore it throws, so the group can't cancel the other calls until the delegate returns. If another call fails during that wait, its error can reach the group first, and the delegate hears about both failures. Could the failure cancel the round first, and then report to the delegate only the error that the round throws? A test with a slowdidFailToolCalland two failing tools would cover it. didExecuteToolCallnow runs as each call finishes, so the delegate hears about calls in the order they complete, and the callbacks can overlap. Before, it heard about them in the model's order, one at a time, and I'd like to keep that. Could the calls still run at once, but report to the delegate in the model's order, one at a time? A test where the calls finish in reverse order would cover it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #359.
The calls a model makes in one round now run concurrently, in every provider whose tool loop runs in the library, through one shared resolver (
resolveToolRoundinShared/ToolRound.swift). It replaces the seven near-identical copies in Anthropic, Gemini, Ollama, OpenAI, Open Responses, MLX and llama.cpp.As discussed in the issue:
Sendableand may call a tool concurrently with itself or with other tools. A tool that isn't safe to run alongside others can serialize its own work. There's no setting.parallel_tool_callsis unchanged. It governs what the model may ask for, not how the calls run..stopstill ends the round before any call runs.Two 300 ms calls in one round now take about 0.3 s instead of 0.6 s.
Tests
ToolRoundTestscovers:.stop;The full suite has the same failures as
mainhere: the 13 tests that need live services.The README's Tool Calling section notes that calls run at once.
🤖 Generated with Claude Code
https://claude.ai/code/session_01B4WBsc1Jp8fGufe89MhQFB