Skip to content

fix: preserve thought_signature across parallel tool calls for Gemini 3+ - #1000

Merged
toubatbrian merged 2 commits into
mainfrom
brian/fix-gemini-thought-signature
Jan 27, 2026
Merged

fix: preserve thought_signature across parallel tool calls for Gemini 3+#1000
toubatbrian merged 2 commits into
mainfrom
brian/fix-gemini-thought-signature

Conversation

@toubatbrian

@toubatbrian toubatbrian commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Fixes a 400 error when using Gemini 3+ models with parallel tool calls. The thought_signature is now correctly propagated to all tool calls in a batch instead of only the first one. Also removes a hardcoded parallelToolCalls: true in the voice pipeline that was overriding user configuration.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed preservation of context signatures across parallel tool calls for Gemini 3+ models to improve inference quality with the inference gateway.
  • Chores

    • Updated configuration to use model options for controlling parallel tool call behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot

changeset-bot Bot commented Jan 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c1d079

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR modifies how tool extra data (thought_signature) is preserved during parallel tool calls in Gemini 3+ models, and updates the Agent's LLM configuration to rely on modelOptions for controlling parallel tool call behavior instead of hardcoded settings.

Changes

Cohort / File(s) Summary
Semantic Release Configuration
.changeset/salty-regions-relate.md
New changeset file declaring a patch release for @livekit/agents with a note about preserving thought_signature across parallel tool calls for Gemini 3+.
LLM Tool Call Streaming
agents/src/inference/llm.ts
Modified tool-call streaming logic to preserve toolExtra across parallel tool calls within a batch, allowing subsequent tool calls to inherit thought_signature from the first call. toolExtra is conditionally updated only when extra_content exists on the current tool call; otherwise, the previous value is retained. Reset now occurs at the end of the response batch to prevent leakage into subsequent responses.
Voice Agent Configuration
agents/src/voice/agent.ts
Removed explicit parallelToolCalls: true setting from LLM chat API calls. Agent now relies on the LLM's modelOptions (e.g., parallel_tool_calls) to control parallelism, with added comments explaining configuration via new inference.LLM({ modelOptions: { parallel_tool_calls: false } }).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • lukasIO
  • theomonnom

Poem

🐰 A thought preserved through whispered calls,
Where Gemini's tools dance through parallel halls,
No hardcoding chains, just options that flow,
The signature passes—let inference go! 🌙

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is minimal and does not follow the provided template structure with required sections like 'Changes Made' and 'Pre-Review Checklist'. Expand the description to follow the template format, including detailed 'Changes Made' section and complete pre-review checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: preserving thought_signature across parallel tool calls for Gemini 3+, which directly corresponds to the primary change in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebfb82f and 5c1d079.

📒 Files selected for processing (3)
  • .changeset/salty-regions-relate.md
  • agents/src/inference/llm.ts
  • agents/src/voice/agent.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/agent-core.mdc)

Add SPDX-FileCopyrightText and SPDX-License-Identifier headers to all newly added files with '// SPDX-FileCopyrightText: 2025 LiveKit, Inc.' and '// SPDX-License-Identifier: Apache-2.0'

Files:

  • agents/src/inference/llm.ts
  • agents/src/voice/agent.ts
**/*.{ts,tsx}?(test|example|spec)

📄 CodeRabbit inference engine (.cursor/rules/agent-core.mdc)

When testing inference LLM, always use full model names from agents/src/inference/models.ts (e.g., 'openai/gpt-4o-mini' instead of 'gpt-4o-mini')

Files:

  • agents/src/inference/llm.ts
  • agents/src/voice/agent.ts
**/*.{ts,tsx}?(test|example)

📄 CodeRabbit inference engine (.cursor/rules/agent-core.mdc)

Initialize logger before using any LLM functionality with initializeLogger({ pretty: true }) from '@livekit/agents'

Files:

  • agents/src/inference/llm.ts
  • agents/src/voice/agent.ts
🧠 Learnings (2)
📚 Learning: 2026-01-16T14:33:39.551Z
Learnt from: CR
Repo: livekit/agents-js PR: 0
File: .cursor/rules/agent-core.mdc:0-0
Timestamp: 2026-01-16T14:33:39.551Z
Learning: Applies to **/{examples,test}/**/*.test.ts : Include both basic streaming and tool calling tests to verify full LLM functionality

Applied to files:

  • agents/src/inference/llm.ts
📚 Learning: 2026-01-16T14:33:39.551Z
Learnt from: CR
Repo: livekit/agents-js PR: 0
File: .cursor/rules/agent-core.mdc:0-0
Timestamp: 2026-01-16T14:33:39.551Z
Learning: Applies to **/*.{ts,tsx}?(test|example|spec) : When testing inference LLM, always use full model names from `agents/src/inference/models.ts` (e.g., 'openai/gpt-4o-mini' instead of 'gpt-4o-mini')

Applied to files:

  • agents/src/inference/llm.ts
  • agents/src/voice/agent.ts
🔇 Additional comments (4)
.changeset/salty-regions-relate.md (1)

1-5: Clear changeset entry

The patch release note matches the behavior change and is concise.

agents/src/inference/llm.ts (2)

431-456: Preserving toolExtra across parallel tool calls is consistent with Gemini behavior

Line 436–456 keeps the thought_signature available for subsequent tool calls in the same batch, which fits the stated goal.


468-477: Good safeguard resetting toolExtra at response end

Line 475–476 prevents metadata leakage across responses while still supporting parallel batches.

agents/src/voice/agent.ts (1)

331-333: Configurable parallel tool calls is a good default

Line 331–333 makes parallelism follow modelOptions, which is clearer and more flexible for users.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread agents/src/voice/agent.ts
toolCtx,
toolChoice,
connOptions,
parallelToolCalls: true,

@toubatbrian toubatbrian Jan 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: although this was hardcoded to true, the actual value was still correctly been overriden by user config inside LLM in previous version.

@toubatbrian
toubatbrian requested a review from a team January 27, 2026 01:27

@Hormold Hormold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it works for me

@toubatbrian
toubatbrian merged commit 217eb7d into main Jan 27, 2026
8 checks passed
@toubatbrian
toubatbrian deleted the brian/fix-gemini-thought-signature branch January 27, 2026 01:37
@github-actions github-actions Bot mentioned this pull request Jan 26, 2026
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.

2 participants