Skip to content

Handle multiple tool calls in ChatSession - #162

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
alankessler:fix-multiple-tool-calls
Mar 27, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
alankessler:fix-multiple-tool-calls

Conversation

@alankessler

Copy link
Copy Markdown
Contributor

Fixes #134.

The generation loop was breaking on the first tool call, canceling the stream, and losing the rest. Now it drains the stream, collects all tool calls, dispatches them, and restarts with all tool results. Works for both mid-stream (JSON/XML tagged) and EOS-emitted (Mistral) tool calls.

Skips dispatch if the consumer has canceled. No change to the streamDetails path — callers without toolDispatch still get tool call items directly.

The generation loop was breaking on the first tool call, canceling the
stream, and losing the rest. Now it drains the stream, collects all
tool calls, dispatches them, and restarts with all tool results.

Skips dispatch if the consumer has canceled (Task.isCancelled).
No change to the streamDetails path.

Fixes ml-explore#134.

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple, thank you!

@davidkoski
davidkoski merged commit 2a296f1 into ml-explore:main Mar 27, 2026
2 checks passed
TheTom referenced this pull request in TheTom/mlx-swift-lm Apr 5, 2026
The generation loop was breaking on the first tool call, canceling the
stream, and losing the rest. Now it drains the stream, collects all
tool calls, dispatches them, and restarts with all tool results.

Skips dispatch if the consumer has canceled (Task.isCancelled).
No change to the streamDetails path.

Fixes ekryski#134.
davidtai added a commit to davidtai/mlx-swift-lm that referenced this pull request Oct 6, 2026
* ci: build the fork and run its Metal test suites

Add the Fork Tests workflow. It builds the package on a macos-26
runner, builds the full MLX Metal library with cmake, copies it next
to the test binaries, and runs six CBv2 paged suites one step each.
A suite step fails when the suite executes zero tests or skips a test.

Port the scripts from d-inference and add them to fork.yaml.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci: remove the empty GPU listing from Fork Tests

system_profiler SPDisplaysDataType prints nothing on the hosted
macos-26 VM. The CPU, memory and disk lines stay.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci: test the nested-suite tripwire

Add scripts/test-run-nested-suite.sh. It runs run-nested-suite.sh
with a fake swift command and checks the exit code for 12 outputs:
passing XCTest and Swift Testing runs, zero executed tests, no output,
an XCTest skip, Swift Testing skips with the Swift 6.1 symbol, the
Swift 6.3 symbol, no symbol and no reason, a suite skip, test output
that contains the word "skipped", and a failing swift test. It also
checks the arguments that swift gets.

Run it as the first step of Fork Tests and list it in fork.yaml.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci: select the newest release of Xcode 26 in Fork Tests

Pick the newest Xcode_26.x app whose name is only a version number.
Beta and release candidate apps are left out, so a new beta on the
runner image cannot change CI without a pull request. The step still
fails when the selected Swift is older than 6.3.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci: correct the Metal library notes in build-metallib.sh

swift build makes no Metal library. The pinned mlx-swift excludes the
MLX kernel sources and nojit_kernels.cpp from Cmlx, so SwiftPM builds
MLX in JIT mode, and every MLX operation traps without a staged
mlx.metallib. The partial 459-symbol library comes from xcodebuild,
which this workflow does not use.

State that the 10,000-symbol floor rejects a JIT-mode or incomplete
cmake build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci: key the SwiftPM cache on the commit and clean it before saving

End the cache key with the commit SHA, as d-inference does, so each
push to main saves a new entry. The prefix restore key still restores
the newest entry for the same Xcode.

Before the save, delete the staged mlx.metallib copies and the
coverage data, so the cache keeps only SwiftPM output.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci: fix wording in the Fork Tests files

- run-nested-suite.sh: the suites need no model weights, but one test
  needs DARKBLOOM_EXCLUSIVE_NATIVE_GPU_TEST=1, which the caller sets.
- fork-tests.yml: runs on main are not cancelled once they start.
- Say "self-contained" instead of "hermetic" in the workflow and in
  fork.yaml.
- fork.yaml: write the Fork Tests paragraph as one sentence per line,
  so later pull requests can add a sentence without touching the same
  lines.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci: test more skip forms and the paged kernel runner

- Add a case for the plural XCTest skip line, "with 2 tests skipped".
- Remove the third skip pattern, "skipped N test", from
  run-nested-suite.sh. No current tool prints it: Swift Testing prints
  one "skipped" line for each test and no skip count, XCTest prints
  "with N test(s) skipped", and SwiftPM prints neither.
- Test run-paged-kernel-tests.sh with a fake swift that answers per
  filter: both processes pass; the first fails and the second still
  runs; the second fails; the first executes zero tests. Check that
  the first process runs without DARKBLOOM_EXCLUSIVE_NATIVE_GPU_TEST
  and the second with it set to 1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ChatSession should handle multiple tool calls

2 participants