Skip to content

Support correlated tool call transcripts - #360

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:tool_id_for_lampo
Jun 29, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:tool_id_for_lampo

Conversation

@aleroot

@aleroot aleroot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

This PR adds the missing transcript representation and default message-generation support for correlated tool calls. Model-specific generators can build on this where needed.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@ronaldmannak

Copy link
Copy Markdown
Contributor

As mentioned in #246:

Thanks for the follow-up @davidkoski and @aleroot.

I think the best way forward is to close this PR and use #360 as the foundation, since it seems to model and enforce message correctness better.

That said, I think #360 still needs one follow-up improvement: missing tool-call IDs should be normalized/generated before the calls are exposed to the caller.

Suggested behavior:

if parsedToolCall.id == nil {
    parsedToolCall.id = generateToolCallID()
}

The generated ID should then stay attached to the assistant ToolCall, and callers should use that same ID when appending the corresponding tool-result message.

It may also be worth adding tests for:

  • preserving provider/model-supplied tool-call IDs;
  • generating IDs for parsed tool calls that do not include one;
  • ensuring generated IDs are distinct for multiple tool calls in one assistant turn;
  • serializing tool-result messages with the matching tool_call_id;
  • preventing or detecting duplicate IDs in a single assistant turn;
  • preventing orphan tool-result messages that reference no prior assistant tool call.

@aleroot
aleroot force-pushed the tool_id_for_lampo branch from 713af00 to 1821c09 Compare June 23, 2026 13:45
@aleroot

aleroot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

@ronaldmannak Thanks for the feedback, I have updated.

Comment thread Tests/MLXLMTests/ToolCallIdTests.swift Resolved
@aleroot
aleroot force-pushed the tool_id_for_lampo branch from 0aabf37 to 1081192 Compare June 25, 2026 18:09
@aleroot
aleroot force-pushed the tool_id_for_lampo branch from 1081192 to 57d5ca1 Compare June 25, 2026 18:26
@aleroot aleroot mentioned this pull request Jun 28, 2026
4 tasks done

@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.

Change looks great, thank you!

@davidkoski
davidkoski merged commit 4cea9e5 into ml-explore:main Jun 29, 2026
2 checks passed
dkgv pushed a commit to dkgv/mlx-swift-lm that referenced this pull request Jul 30, 2026
Support correlated tool call transcripts

Add tool-call IDs so assistant tool calls and tool results can be
correlated in transcripts.

- Add optional `ToolCall.id`; parsers (JSON/Llama3/Mistral) extract
  supplied ids, including OpenAI-style top-level and nested forms
- Add `Chat.Message.Tool` metadata and `MessageGenerator.addToolMetadata`,
  emitting OpenAI-style `tool_calls` / `tool_call_id`; wire through all
  six VLM generators and `DefaultMessageGenerator`
- ToolCallProcessor dedups and regenerates ids per turn, with
  format-aware generation (9-char for Mistral, `call_`-prefixed default)
- ChatSession pairs each tool result with its originating call id
div0-space pushed a commit to LibraxisAI/mlx-swift-lm that referenced this pull request Nov 29, 2026
Merges origin/main aee6ebb into darkbloom/tp-engine 8411247. Main is 377
commits past the merge base 889fe3c: the upstream sync to ml-explore
d02948b (ml-explore#339), the mlx-swift pin eedca444 (ml-explore#358), the provider 0.10.2 set
(ml-explore#356, ml-explore#357, ml-explore#359, ml-explore#360), GLM long-context decode (ml-explore#362), balanced
checkpoints for GLM-5.3-Flash and Nemotron Super (ml-explore#363), GLM video at the
track's average rate (ml-explore#340) and the Flint decode work (ml-explore#336-ml-explore#338).

Package.swift keeps the cluster's mlx-swift pin 9fe34405; everything else
is main's (swift-tools 6.2, the swift-syntax 602 floor, the new targets).

Conflicts:
- GLM5NextMoEDecodeKernel.swift: the cluster's file (the dense-MLP
  two-launch path, the non-private header) in main's swift-format layout,
  with main's two changes: GLM5NextNVFP4Linear.weightScale2 (renamed
  because MLXNN QuantizedLinear now declares globalScale) and the copied
  MLX sigmoid with metal::precise::exp (main 1ba5e73).
- PagedSegmentAttention.swift: main's first-bucket scratch allocation and
  seqinfo cache, plus the cluster's multi-query verification kernel and
  the non-private merge kernel it uses.
- GatedDelta.swift: main moved it to MLXLMCommon and added useKernel. The
  cluster's fuseQwen35Gates stays; its compiled gates move beside
  gatedDeltaUpdate (qwen35GatedDeltaGates, package) because MLXLMCommon
  cannot reach MLXLLM's Qwen35DecodeFusions, which now forwards to it. The
  traced ops are the cluster's (sigmoid(b) to float32, then
  exp(-exp(float32(A_log)) * softplus(a + dt_bias))), so the decode gates
  keep their bits. Qwen35DecodeFusionsTests compares against the separate
  ops, since main made computeGatedDeltaG itself a compiled closure.
- GLM5NextProcessor.swift: main's image.source switch with the cluster's
  GLM5NextRGBDecoder; main's variable-frame-rate decoding auto-merged.
- Package.swift: see above.

Merged without textual conflict but adjusted:
- PagedLayerCache.writePromptKVWithoutAttention (main, Flint) advances
  the offsets through advancePositionOffsets, so the cluster's
  hostPositionOffsets stay in step with the device offsets.
- PagedAttentionKVTests: main's newCache throws.

Numerics: main changed every copied MLX sigmoid to metal::precise::exp
(1ba5e73, 3794edf) to follow MLX #4461: the GLM hyper-connection
coefficients, the GLM MoE decode and prefill clamped GLU, Nemotron Super
and MiMo. They follow the merged MLX core. The cluster core pinned here
still has metal::exp, so GLM on the pair changes bits when it runs with
these kernels; see the merge record.

Tests: swift build --build-tests against main's mlx-swift eedca444 with
two compile-only stand-ins for the cluster mlx-swift API
(MLXArray.sharingArray, metalKernel fencedInputs): complete. The CPU unit
group (^MLXLMTests.UnitTests/, no Metal library): 437 tests, one failure,
the pre-existing GLM5NextProcessorMediaTests Metal dependency. The tree
does not build at its own pin 9fe34405 (main needs mlx-swift API such as
MLXArray.maskFill); it builds once the pin moves to the merged mlx-swift.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

3 participants