Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 13, 2025

Related GitHub Issue

Closes: #10064

Roo Code Task Context (Optional)

This PR was created by Roomote to address the issue.

Description

This PR adds support for extracting tool calls from Kimi K2 Thinking model responses when using the OpenAI Compatible provider.

The Kimi K2 Thinking model embeds tool calls in the reasoning_content field using special tags (<|tool_calls_section_begin|>, <|tool_call_begin|>, etc.) rather than the standard OpenAI tool_calls field. This caused the "no message content" error reported in the issue.

Key implementation details:

  • Added kimi-tool-call-extractor.ts utility to parse embedded tool calls from reasoning content
  • Updated the OpenAI handler to detect kimi-k2-thinking models and extract embedded tool calls
  • Supports both streaming and non-streaming modes
  • Handles multiple tool calls in a single response

Test Procedure

  1. Unit tests added for the new kimi-tool-call-extractor utility covering:

    • Detection of embedded tool call markers
    • Extraction of single and multiple tool calls
    • Model name detection (case insensitive, various formats)
    • Cleaning of reasoning content after extraction
  2. Existing OpenAI handler tests continue to pass

Run tests:

cd src && npx vitest run api/providers/utils/__tests__/kimi-tool-call-extractor.spec.ts
cd src && npx vitest run api/providers/__tests__/openai.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - Backend API handling changes only

Documentation Updates

  • No documentation updates are required.

Additional Notes

This implementation is based on the code example provided by @bozoweed in issue #10064 and the Kimi K2 Thinking tool call guidance.

Feedback and guidance are welcome!

Get in Touch

Roomote Bot

This adds support for extracting tool calls from Kimi K2 Thinking model
responses when using the OpenAI Compatible provider. The Kimi K2 Thinking
model embeds tool calls in the reasoning_content field using special tags
rather than the standard tool_calls field.

Changes:
- Added kimi-tool-call-extractor utility to parse embedded tool calls
- Updated OpenAI handler to detect and extract embedded tool calls
- Added comprehensive tests for the new functionality

Fixes #10064
@roomote
Copy link
Contributor Author

roomote bot commented Dec 13, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The latest commit correctly addresses the feedback about handling tool call markers with or without <| |> delimiters:

  • Detection function now checks for core marker text (tool_calls_section_begin)
  • Regex patterns updated to make delimiters optional
  • Test coverage added for both delimiter formats
  • Changes are backward compatible
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 13, 2025
* Checks if the content contains Kimi K2 Thinking model's embedded tool call markers.
*/
export function hasKimiEmbeddedToolCalls(content: string): boolean {
return content.includes("<|tool_calls_section_begin|>")

Choose a reason for hiding this comment

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

take care some time it's formed as <|tool_calls_section_begin|> use only tool_calls_section_begin is working like a charmed

Choose a reason for hiding this comment

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

@roomote fix that please

Copy link
Contributor Author

@roomote roomote bot Dec 13, 2025

Choose a reason for hiding this comment

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

Fixaroo Clock   See task on Roo Cloud

Fixed the tool call marker detection to handle both <|marker|> and marker formats. All local checks passed.

View commit | Revert commit

@bozoweed
Copy link

Date/time: 2025-12-17T07:22:48.014Z
Extension version: 3.36.9
Provider: openai
Model: moonshotai/kimi-k2-thinking

Unexpected API Response: The language model did not provide any assistant messages. This may indicate an issue with the API or the model's output.

any plan to work on that ..... you just add deepseek reasoner but seem that you don't support OpenAi Compatible for deepseek-reasoner .... please .... i hardly need to use that model on OpenAi Compatible way ....

@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 7, 2026
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Kimi k2 thinking not supported on OpenAi Compatible

4 participants