Skip to content

fix: add id to Message.ToolCall and tool_call_id to Message (#667) - #769

Open
Madhavkannank wants to merge 2 commits into
ollama:mainfrom
Madhavkannank:fix/tool-call-id
Open

Madhavkannank wants to merge 2 commits into
ollama:mainfrom
Madhavkannank:fix/tool-call-id

Conversation

@Madhavkannank

@Madhavkannank Madhavkannank commented Oct 19, 2026 •

Copy link
Copy Markdown

Description

The Ollama Go server backend exposes both ToolCall.ID (when a model requests a tool call) and Message.ToolCallID (when returning a role: "tool" execution result back to the model, as seen in ollama/api/types.go).

Previously in ollama-python:

  1. Message.ToolCall lacked the id field, causing server-returned tool call IDs to be dropped.
  2. Message lacked the tool_call_id field, causing incoming role: "tool" messages in _copy_messages() to drop tool_call_id during Message.model_validate(...) serialization.

This PR provides the complete two-way tool correlation fix, directly resolving the missing tool-result correlation identified in PR #712.

Changes

  • Added id: Optional[str] = None to Message.ToolCall in ollama/_types.py.
  • Added tool_call_id: Optional[str] = None to Message in ollama/_types.py.
  • Added regression tests in tests/test_client.py for both Client.chat and AsyncClient.chat verifying:
    • Tool call id parsing from server responses
    • Subscript indexing access (tool_call['id'])
    • Backward compatibility when id is omitted by the server
    • Pydantic serialization round-trip (model_dump())
    • Tool result round-trip: preserving tool_call_id on role: "tool" messages through _copy_messages() into outbound /api/chat requests.

Fixes #667

Copilot AI balanced review requested due to automatic review settings October 19, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved issues were identified, and the requested behavior is covered by regression tests.

No open issues 🎉

Review effort: Lite

@Madhavkannank Madhavkannank changed the title fix: add missing id field to Message.ToolCall (#667) fix: add id to Message.ToolCall and tool_call_id to Message (#667) Oct 19, 2026
@Madhavkannank
Madhavkannank requested a lite review from Copilot October 19, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The reviewed changes are covered by regression tests and have no unresolved blocking issues.

No open issues 🎉

Review effort: Lite

This branch has not been deployed

No deployments
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.

id in ToolCall missing

2 participants