Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore: Support Interleaved thinking in kimi-k2-thinking (#10256)

sxjeru9f20ec4135df
diff --git a/packages/model-bank/src/aiModels/moonshot.ts b/packages/model-bank/src/aiModels/moonshot.ts
index 1a8d6b98c16..dc22acf740b 100644
--- a/packages/model-bank/src/aiModels/moonshot.ts
+++ b/packages/model-bank/src/aiModels/moonshot.ts
@@ -2,6 +2,52 @@ import { AIChatModelCard } from '../types/aiModel';
// https://platform.moonshot.cn/docs/pricing/chat
const moonshotChatModels: AIChatModelCard[] = [
+ {
+ abilities: {
+ functionCall: true,
+ reasoning: true,
+ structuredOutput: true,
+ },
+ contextWindowTokens: 262_144,
+ description: 'K2 长思考模型,支持 256k 上下文,支持多步工具调用与思考,擅长解决更复杂的问题。',
+ displayName: 'Kimi K2 Thinking',
+ enabled: true,
+ id: 'kimi-k2-thinking',
+ maxOutput: 65_536,
+ pricing: {
+ currency: 'CNY',
+ units: [
+ { name: 'textInput_cacheRead', rate: 1, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput', rate: 4, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 16, strategy: 'fixed', unit: 'millionTokens' },
+ ],
+ },
+ releasedAt: '2025-11-06',
+ type: 'chat',
+ },
+ {
+ abilities: {
+ functionCall: true,
+ reasoning: true,
+ structuredOutput: true,
+ },
+ contextWindowTokens: 262_144,
+ description:
+ 'K2 长思考模型的高速版本,支持 256k 上下文,擅长深度推理,输出速度提升至每秒 60-100 tokens 。',
+ displayName: 'Kimi K2 Thinking Turbo',
+ id: 'kimi-k2-thinking-turbo',
+ maxOutput: 65_536,
+ pricing: {
+ currency: 'CNY',
+ units: [
+ { name: 'textInput_cacheRead', rate: 1, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput', rate: 8, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 58, strategy: 'fixed', unit: 'millionTokens' },
+ ],
+ },
+ releasedAt: '2025-11-06',
+ type: 'chat',
+ },
{
abilities: {
functionCall: true,
diff --git a/packages/model-runtime/src/core/contextBuilders/openai.ts b/packages/model-runtime/src/core/contextBuilders/openai.ts
index 993ab51a6b9..d59d6a18484 100644
--- a/packages/model-runtime/src/core/contextBuilders/openai.ts
+++ b/packages/model-runtime/src/core/contextBuilders/openai.ts
@@ -49,7 +49,7 @@ export const convertOpenAIMessages = async (messages: OpenAI.ChatCompletionMessa
if (msg.tool_call_id !== undefined) result.tool_call_id = msg.tool_call_id;
if (msg.function_call !== undefined) result.function_call = msg.function_call;
- // it's compatible for DeepSeek
+ // it's compatible for DeepSeek & Moonshot
if (msg.reasoning_content !== undefined) result.reasoning_content = msg.reasoning_content;
// MiniMax uses reasoning_details for historical thinking, so forward it unchanged
if (msg.reasoning_details !== undefined) result.reasoning_details = msg.reasoning_details;
diff --git a/packages/model-runtime/src/providers/moonshot/index.ts b/packages/model-runtime/src/providers/moonshot/index.ts
index aaaa189e983..c2d12389e40 100644
--- a/packages/model-runtime/src/providers/moonshot/index.ts
+++ b/packages/model-runtime/src/providers/moonshot/index.ts
@@ -18,12 +18,25 @@ export const params = {
handlePayload: (payload: ChatStreamPayload) => {
const { enabledSearch, messages, temperature, tools, ...rest } = payload;
- // 为 assistant 空消息添加一个空格 (#8418)
- const filteredMessages = messages.map((message) => {
+ const filteredMessages = messages.map((message: any) => {
+ let normalizedMessage = message;
+
+ // 为 assistant 空消息添加一个空格 (#8418)
if (message.role === 'assistant' && (!message.content || message.content === '')) {
- return { ...message, content: ' ' };
+ normalizedMessage = { ...normalizedMessage, content: ' ' };
+ }
+
+ // Interleaved thinking
+ if (message.role === 'assistant' && message.reasoning) {
+ const { reasoning, ...messageWithoutReasoning } = normalizedMessage;
+ return {
+ ...messageWithoutReasoning,
+ ...(!reasoning.signature && reasoning.content
+ ? { reasoning_content: reasoning.content }
+ : {}),
+ };
}
- return message;
+ return normalizedMessage;
});
const moonshotTools = enabledSearch