fix(types): expose tool call id on Message.ToolCall#698
Open
winklemad wants to merge 1 commit into
Open
Conversation
The server returns an id on each tool call (e.g. "call_p7o2gz50"), but ToolCall had no id field, so it was dropped and wasn't in model_extra either. Add an optional id field so it round-trips. Fixes ollama#667
76c2183 to
baf8dbb
Compare
vaderollama
approved these changes
Jul 14, 2026
vaderollama
left a comment
There was a problem hiding this comment.
LGTM — adds the missing id field to Message.ToolCall matching the Go API (ToolCall.Id in api/types.go). Backwards-compatible (optional, defaults to None), tests cover round-tripping and default. Resolves #667.
@ParthSareen — ready to merge.
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.
What & why
The Ollama server returns an
idon each tool call in the response, e.g.{"id": "call_p7o2gz50", "function": {...}}. ButMessage.ToolCallhas noidfield, so it's silently dropped — and it isn't inmodel_extraeither — leaving no way to read the tool-call id from Python (#667). That id is needed to correlate a tool call with its result.Change
Add an optional
id: Optional[str] = NonetoMessage.ToolCall. It's optional/defaulted so responses that omit it (older servers) keep parsing unchanged.Testing
tests/test_type_serialization.py: the id round-trips from a raw response and serializes back viamodel_dump(), and defaults toNonewhen absent. Full suite: 94 passed.ruff check+ruff formatclean.Fixes #667