[PR #5054] [MERGED] fix: resolve Gemini agent 400 error on tool call responses #5283

Closed
opened 2026-06-05 15:20:50 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5054
Author: @angelplusultra
Created: 2/23/2026
Status: Merged
Merged: 2/26/2026
Merged by: @timothycarambat

Base: masterHead: 5030-bug-geministream-in-aibitat-failing-to-process-the-web-search-agent


📝 Commits (4)

  • ccaa455 add gtc__ prefix to tool call names in Gemini agent message formatting
  • 0de1a38 resolve Gemini agent 400 error on tool call responses
  • d0891f4 add comments explaining geminis thought signatures
  • 2cb8e42 Merge branch 'master' into 5030-bug-geministream-in-aibitat-failing-to-process-the-web-search-agent

📊 Changes

1 file changed (+19 additions, -1 deletions)

View changed files

📝 server/utils/agents/aibitat/providers/gemini.js (+19 -1)

📄 Description

Pull Request Type

  • feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #5030

Description

When using Gemini as the LLM provider with agents, tool calls (e.g., web search) would succeed on the first API call but fail with a 400 (no body) error on the second call — when handing tool results back to Gemini for processing.

Three issues were identified and fixed in the Gemini provider's message formatting:

  1. Missing thought signature: Gemini now requires a thought_signature (via extra_content.google.thought_signature) on function call parts in multi-turn tool conversations. The streaming and non-streaming paths were not capturing this field from Gemini's response, so it was lost when reconstructing the assistant message for subsequent API calls. Both stream() and complete() now preserve extra_content through the originalFunctionCall pipeline.

  2. Missing gtc__ prefix on tool call names: The stream() method strips the gtc__ prefix from function names before returning to the aibitat framework, but #formatMessages() was not re-adding it when reconstructing historical tool call messages. This caused a name mismatch between the tool definitions and the conversation history.

  3. Missing fields on formatted messages: Gemini's OpenAI-compatible endpoint requires content on assistant tool_calls messages and name on tool response messages — fields that standard OpenAI does not require.

This fix only affects the Gemini provider.

Visuals (if applicable)

N/A

Additional Information

Gemini thought signatures reference: https://ai.google.dev/gemini-api/docs/thought-signatures

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 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/Mintplex-Labs/anything-llm/pull/5054 **Author:** [@angelplusultra](https://github.com/angelplusultra) **Created:** 2/23/2026 **Status:** ✅ Merged **Merged:** 2/26/2026 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `5030-bug-geministream-in-aibitat-failing-to-process-the-web-search-agent` --- ### 📝 Commits (4) - [`ccaa455`](https://github.com/Mintplex-Labs/anything-llm/commit/ccaa455061f65d5bfec9d73028b1f77bbe662434) add gtc__ prefix to tool call names in Gemini agent message formatting - [`0de1a38`](https://github.com/Mintplex-Labs/anything-llm/commit/0de1a38a037ba098001d96b483f9bb6dd30c5d50) resolve Gemini agent 400 error on tool call responses - [`d0891f4`](https://github.com/Mintplex-Labs/anything-llm/commit/d0891f4053eba1d07b6847f09287155bb6f6285c) add comments explaining geminis thought signatures - [`2cb8e42`](https://github.com/Mintplex-Labs/anything-llm/commit/2cb8e42aa41334029ad7d3d4bf35cdb8605858b8) Merge branch 'master' into 5030-bug-geministream-in-aibitat-failing-to-process-the-web-search-agent ### 📊 Changes **1 file changed** (+19 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `server/utils/agents/aibitat/providers/gemini.js` (+19 -1) </details> ### 📄 Description ### Pull Request Type - [ ] ✨ feat (New feature) - [x] 🐛 fix (Bug fix) - [ ] ♻️ refactor (Code refactoring without changing behavior) - [ ] 💄 style (UI style changes) - [ ] 🔨 chore (Build, CI, maintenance) - [ ] 📝 docs (Documentation updates) ### Relevant Issues resolves #5030 ### Description When using Gemini as the LLM provider with agents, tool calls (e.g., web search) would succeed on the first API call but fail with a `400 (no body)` error on the second call — when handing tool results back to Gemini for processing. Three issues were identified and fixed in the Gemini provider's message formatting: 1. **Missing thought signature**: Gemini now requires a `thought_signature` (via `extra_content.google.thought_signature`) on function call parts in multi-turn tool conversations. The streaming and non-streaming paths were not capturing this field from Gemini's response, so it was lost when reconstructing the assistant message for subsequent API calls. Both `stream()` and `complete()` now preserve `extra_content` through the `originalFunctionCall` pipeline. 2. **Missing `gtc__` prefix on tool call names**: The `stream()` method strips the `gtc__` prefix from function names before returning to the aibitat framework, but `#formatMessages()` was not re-adding it when reconstructing historical tool call messages. This caused a name mismatch between the tool definitions and the conversation history. 3. **Missing fields on formatted messages**: Gemini's OpenAI-compatible endpoint requires `content` on assistant tool_calls messages and `name` on tool response messages — fields that standard OpenAI does not require. This fix only affects the Gemini provider. ### Visuals (if applicable) N/A ### Additional Information Gemini thought signatures reference: https://ai.google.dev/gemini-api/docs/thought-signatures ### Developer Validations - [x] I ran `yarn lint` from the root of the repo & committed changes - [ ] Relevant documentation has been updated (if applicable) - [x] I have tested my code functionality - [ ] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:20:50 -04:00
yindo closed this issue 2026-06-05 15:20:50 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5283