Repository navigation
Add tool-call id round-trip for OpenClaw / Hermes-style tool calling - #246
ronaldmannak wants to merge 2 commits into
Conversation
|
I’m hesitant about this PR. The API makes At minimum, this PR should not recommend UUIDs as the default pattern, and it should include a tokenizer-template smoke test proving that the generated This also seems related to my open pull request #205. That PR keeps tool-call handling in the parser/processor layer, where we know the active tool-call format and can use the provided tool schemas to decide whether emitted JSON is actually a tool call. I think that is the safer direction here too. Tool-call IDs are not purely generic metadata; they can be constrained by the model family or tokenizer chat template. So if we add ID support, I’d expect it to preserve parser-provided IDs first, validate or synthesize IDs according to the active format/template where needed, and only then expose a higher-level history API. Right now this feels like exposing an OpenAI-shaped field in the generic chat API without enough guarantees that it is correct for the model family actually being used. @davidkoski what do you think of it? |
|
@aleroot Thanks for the detailed review. I think I understand the concerns as:
That makes sense. I was thinking of this mainly as the history-correlation field needed to echo an assistant tool call back with the corresponding tool result, but I agree the PR description should not recommend On Mistral specifically: the Tokenizer V3 docs show the assistant tool call carrying an Where I’m less sure is the final public API shape. Even if ID creation/validation is format-aware, the app still needs some structured way to send the result back with the matching call ID. That might be Re #205, I also opened #214 recently, and I think these are related pieces of a broader response-parsing problem. Gemma 4 and GPT-oss are good examples of models with richer response formats that the current code does not handle well, and that seems to be outside the scope of #205. Since tool-call IDs need parser-level preservation for formats like Mistral, maybe this is a good moment to decide whether IDs should be added as part of a more complete response-parsing abstraction rather than only as fields on I know @angeloskath had, or will soon have, a call about response parsing, so it may be worth aligning this PR with that direction before locking in the public API. |
|
Where are we on this one? I don't think Angelos has anything new on the mlx-lm side (I could be wrong). I have wanted to think through how we could integrate various types of response handling but haven't had the time. If this is a missing feature it seems like it might be worth getting in even if we have a new way to implement it a few months down the road. Thoughts? |
|
@ronaldmannak @davidkoski I am sorry but I totally forgot about this pull request and today I have opened this one: #360 . The id is indeed necessary, the id is indeed necessary, especially for multi-turn tool calling where the tool result needs to be linked back to the assistant tool call it answers. @ronaldmannak if you want to look at my approach and adapt this PR, or if we prefer to move forward with #360, either is fine with me. The important thing is that we converge on one API shape and have the id implemented. |
|
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:
I'm closing this PR and will copy and paste this message in #360 as well |
…ed into stacked branches) (ml-explore#246)
Proposed changes
Multi-turn tool calling needs each tool result to reference the call it answers. This PR adds an optional id end-to-end.
Calling application supplies its own id (e.g. a UUID) and threads it through
ToolCall(id:, function:)andChat.Message.tool(_:id:).All new fields default to
niland all new initializer parameters havenildefaults to maintain compatibility.Example:
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes