[PR #14676] Preserve thought signatures in tool calls and messages (fix #14567) #77075

Open
opened 2026-05-05 09:47:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14676
Author: @willificent
Created: 3/6/2026
Status: 🔄 Open

Base: mainHead: fix-gemini-tool-call-missing-signature


📝 Commits (1)

  • c1a1db4 Preserve thought signatures in tool calls and messages

📊 Changes

7 files changed (+250 additions, -11 deletions)

View changed files

📝 anthropic/anthropic.go (+37 -2)
📝 anthropic/anthropic_test.go (+120 -0)
📝 api/types.go (+5 -3)
📝 api/types_test.go (+27 -0)
📝 middleware/anthropic.go (+3 -0)
📝 openai/openai.go (+11 -6)
📝 openai/openai_test.go (+47 -0)

📄 Description

Summary

This PR fixes Issue #14567 where tool calls with Gemini 3 models (and some Anthropic models) would fail with a "400 Bad Request" error.

The root cause was that Ollama's internal api.Message and api.ToolCallFunction structs were missing fields for reasoning signatures (signature and thought_signature). These signatures are mandatory for some models to link a reasoning block to a subsequent tool call in the conversation history. Because Ollama was "lossy" during JSON unmarshaling/remarshaling, these signatures were dropped, making the conversation history invalid for the next turn.

Changes

  • api/types.go: Added Signature to Message struct and ThoughtSignature to ToolCallFunction struct.
  • anthropic/anthropic.go: Updated conversion logic to extract and pass through signatures.
  • openai/openai.go: Updated OpenAI compatibility layer to preserve signatures and reasoning blocks.
  • middleware/anthropic.go: Updated assistant message building and stream conversion to include signatures.
  • Tests: Added regression tests in api, anthropic, and openai packages to ensure these fields are correctly preserved across API boundaries.

Test plan

  • Verified that all modified packages pass tests with go test ./api ./anthropic ./openai.
  • Added specific test cases to api/types_test.go, anthropic/anthropic_test.go, and openai/openai_test.go that verify signature preservation through JSON round-trips.

Fixes #14567

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14676 **Author:** [@willificent](https://github.com/willificent) **Created:** 3/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-gemini-tool-call-missing-signature` --- ### 📝 Commits (1) - [`c1a1db4`](https://github.com/ollama/ollama/commit/c1a1db4d75c8891adb6310b091840f089af9f0bb) Preserve thought signatures in tool calls and messages ### 📊 Changes **7 files changed** (+250 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `anthropic/anthropic.go` (+37 -2) 📝 `anthropic/anthropic_test.go` (+120 -0) 📝 `api/types.go` (+5 -3) 📝 `api/types_test.go` (+27 -0) 📝 `middleware/anthropic.go` (+3 -0) 📝 `openai/openai.go` (+11 -6) 📝 `openai/openai_test.go` (+47 -0) </details> ### 📄 Description ## Summary This PR fixes Issue #14567 where tool calls with Gemini 3 models (and some Anthropic models) would fail with a "400 Bad Request" error. The root cause was that Ollama's internal `api.Message` and `api.ToolCallFunction` structs were missing fields for reasoning signatures (`signature` and `thought_signature`). These signatures are mandatory for some models to link a reasoning block to a subsequent tool call in the conversation history. Because Ollama was "lossy" during JSON unmarshaling/remarshaling, these signatures were dropped, making the conversation history invalid for the next turn. ## Changes - **`api/types.go`**: Added `Signature` to `Message` struct and `ThoughtSignature` to `ToolCallFunction` struct. - **`anthropic/anthropic.go`**: Updated conversion logic to extract and pass through signatures. - **`openai/openai.go`**: Updated OpenAI compatibility layer to preserve signatures and reasoning blocks. - **`middleware/anthropic.go`**: Updated assistant message building and stream conversion to include signatures. - **Tests**: Added regression tests in `api`, `anthropic`, and `openai` packages to ensure these fields are correctly preserved across API boundaries. ## Test plan - Verified that all modified packages pass tests with `go test ./api ./anthropic ./openai`. - Added specific test cases to `api/types_test.go`, `anthropic/anthropic_test.go`, and `openai/openai_test.go` that verify signature preservation through JSON round-trips. Fixes #14567 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 09:47:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#77075