Skip to content

Conversation

@kiloconnect
Copy link
Contributor

@kiloconnect kiloconnect bot commented Dec 20, 2025

Summary

Following PR #4531 which fixed duplicate tool processing in OpenAI-compatible providers, this PR applies the same fix to 7 additional providers that had the same issue.

Problem

The ToolCallAccumulator was processing tool calls in the streaming loop, but the code was also manually emitting tool_call_partial chunks, causing duplicate tool call events to be emitted. This resulted in tools being called twice.

Solution

Remove ToolCallAccumulator usage from the streaming loops and rely solely on emitting raw tool_call_partial chunks, which are properly handled by NativeToolCallParser.

Affected Providers

Also removed unused ToolCallAccumulator import from base-openai-compatible-provider.ts.

Changes Made

For each affected provider:

  1. Removed ToolCallAccumulator import
  2. Removed ToolCallAccumulator instantiation and usage in streaming loop
  3. Added or kept manual emission of tool_call_partial chunks with proper comment

Related Issues

Fixes the same issue as #4529 but for additional providers not covered by PR #4531.

Testing

The fix follows the exact same pattern as PR #4531, which was already tested and merged. Each provider now emits tool call chunks in a consistent way that prevents duplication.

Following PR #4531 which fixed duplicate tool processing in OpenAI-compatible
providers, this change applies the same fix to 7 additional providers that had
the same issue.

The problem: ToolCallAccumulator was processing tool calls in the streaming
loop, but the code was also manually emitting tool_call_partial chunks,
causing duplicates.

The fix: Remove ToolCallAccumulator usage and rely solely on emitting raw
tool_call_partial chunks, which are properly handled by NativeToolCallParser.

Affected providers:
- inception
- lm-studio
- deepinfra
- xai
- lite-llm
- qwen-code
- chutes

Also removed unused ToolCallAccumulator import from base-openai-compatible-provider.

Fixes the same issue as #4529 but for additional providers.
@changeset-bot
Copy link

changeset-bot bot commented Dec 20, 2025

🦋 Changeset detected

Latest commit: 550f7ef

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

This PR includes changesets to release 1 package
Name Type
kilo-code 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

Copy link
Contributor Author

@kiloconnect kiloconnect bot left a comment

Choose a reason for hiding this comment

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

✅ No Issues Found

9 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files:

  • .changeset/fix-duplicate-tool-processing-all-providers.md - Changeset documentation
  • src/api/providers/base-openai-compatible-provider.ts - Removed unused import
  • src/api/providers/chutes.ts - Removed ToolCallAccumulator, kept tool_call_partial emission
  • src/api/providers/deepinfra.ts - Removed ToolCallAccumulator, kept tool_call_partial emission
  • src/api/providers/inception.ts - Removed ToolCallAccumulator, added tool_call_partial emission
  • src/api/providers/lite-llm.ts - Removed ToolCallAccumulator, kept tool_call_partial emission
  • src/api/providers/lm-studio.ts - Removed ToolCallAccumulator, added tool_call_partial emission
  • src/api/providers/qwen-code.ts - Removed ToolCallAccumulator, added tool_call_partial emission
  • src/api/providers/xai.ts - Removed ToolCallAccumulator, kept tool_call_partial emission and processFinishReason

Checked: Security, bugs, code consistency, duplicate processing

Analysis:

  • The fix correctly removes ToolCallAccumulator usage which was causing duplicate tool call events
  • All providers now consistently emit tool_call_partial chunks directly
  • The NativeToolCallParser handles state management for these chunks
  • The pattern matches the established fix from PR #4531
  • The xai.ts provider correctly retains its processFinishReason call (which was already present before this PR)
  • Other providers don't need processFinishReason as they follow the same pattern as openai.ts and base-openai-compatible-provider.ts

@chrarnoldus chrarnoldus deleted the fix/duplicate-tool-processing-all-providers branch December 22, 2025 11:16
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