🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: preserve thinking content semantics (#17053)
Arvin Xuc0fc2ee0a783
diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.tsindex 90693f51fe7..fff0247ef08 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.ts@@ -120,7 +120,7 @@ describe('ServerCallLlmAttempt', () => {const snapshot = attempt.snapshot();expect(snapshot.content).toBe('Visible answer');- expect(snapshot.reasoning).toBe('Reasoning');+ expect(snapshot.thinkingContent).toBe('Reasoning');expect(snapshot.grounding).toEqual({ searchQueries: ['docs'] });expect(snapshot.finishReason).toBe('tool_use');expect(snapshot.speed).toEqual({ tps: 20, ttft: 100 });@@ -198,7 +198,7 @@ describe('ServerCallLlmAttempt', () => {expect.objectContaining({answerSalvagedFromReasoning: true,content: 'Final answer from reasoning',- reasoning: '',+ thinkingContent: '',}),);});diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.tsindex 7c716b32e57..45a1bb27ad1 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.ts@@ -252,9 +252,9 @@ export class ServerCallLlmAttempt {hasContentImages: this.streamSink.hasContentImages,hasReasoningImages: this.streamSink.hasReasoningImages,imageList: [...this.imageList],- reasoning: this.streamSink.thinkingContent,reasoningParts: [...this.streamSink.reasoningParts],speed: this.speed,+ thinkingContent: this.streamSink.thinkingContent,toolCalls: [...this.toolCalls],toolsCalling: [...this.toolsCalling],usage: this.usage,diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmExecutor.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmExecutor.tsindex ad574a1c9a5..145d366cf69 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmExecutor.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmExecutor.ts@@ -158,7 +158,7 @@ class ServerCallLlmTurn {result: {content: llmAttempt.content,finishReason: currentStepFinishReason,- reasoning: llmAttempt.reasoning,+ reasoning: llmAttempt.thinkingContent,tool_calls,usage: currentStepUsage,},@@ -172,7 +172,7 @@ class ServerCallLlmTurn {grounding,...(stepLabel && { stepLabel }),imageList: imageList.length > 0 ? imageList : undefined,- reasoning: llmAttempt.reasoning || undefined,+ reasoning: llmAttempt.thinkingContent || undefined,toolsCalling,usage: currentStepUsage,},diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.test.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.test.tsindex 225e040525e..cc8ff06d4b7 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.test.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.test.ts@@ -1,4 +1,4 @@-import { AgentRuntime } from '@lobechat/agent-runtime';+import { AgentRuntime, type LLMAttemptOutput } from '@lobechat/agent-runtime';import { describe, expect, it, vi } from 'vitest';import type { RuntimeExecutorContext } from '../context';@@ -17,22 +17,25 @@ const createMessageModel = () => {};};+type FinalizerAttemptOutput = Pick<+ LLMAttemptOutput,+ | 'content'+ | 'contentParts'+ | 'hasContentImages'+ | 'hasReasoningImages'+ | 'reasoningParts'+ | 'thinkingContent'+>;+const createStreamOutput = (- overrides?: Partial<{- content: string;- contentParts: Array<{ image: string; type: 'image' } | { text: string; type: 'text' }>;- hasContentImages: boolean;- hasReasoningImages: boolean;- reasoning: string;- reasoningParts: Array<{ image: string; type: 'image' } | { text: string; type: 'text' }>;- }>,-) => ({+ overrides?: Partial<FinalizerAttemptOutput>,+): FinalizerAttemptOutput => ({content: 'Answer',contentParts: [],hasContentImages: false,hasReasoningImages: false,- reasoning: 'Reasoning',reasoningParts: [],+ thinkingContent: 'Reasoning',...overrides,});@@ -160,7 +163,7 @@ describe('serverCallLlmFinalizer', () => {{ text: 'Visual reasoning', type: 'text' },{ image: 'https://example.com/reasoning.png', type: 'image' },],- reasoning: 'Visual reasoning',+ thinkingContent: 'Visual reasoning',}),toolCalls: [],toolsCalling: [],@@ -199,7 +202,7 @@ describe('serverCallLlmFinalizer', () => {assistantMessageId: 'assistant-empty',messageModel,operationLogId: 'operation-1:0',- streamOutput: createStreamOutput({ content: '', reasoning: '' }),+ streamOutput: createStreamOutput({ content: '', thinkingContent: '' }),toolsCalling: [],});expect(update).not.toHaveBeenCalled();@@ -210,7 +213,7 @@ describe('serverCallLlmFinalizer', () => {currentStepUsage: { totalOutputTokens: 4 },messageModel,operationLogId: 'operation-1:0',- streamOutput: createStreamOutput({ content: 'Partial', reasoning: 'Thinking' }),+ streamOutput: createStreamOutput({ content: 'Partial', thinkingContent: 'Thinking' }),toolsCalling: [],});diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.tsindex c6af83c450c..6c2c718b190 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmFinalizer.ts@@ -21,8 +21,8 @@ type ServerCallLlmCollectedOutput = Pick<| 'contentParts'| 'hasContentImages'| 'hasReasoningImages'- | 'reasoning'| 'reasoningParts'+ | 'thinkingContent'>;interface ServerCallLlmMessageMetadata extends MessageMetadata {@@ -93,7 +93,7 @@ const buildFinalReasoning = (};}- return streamOutput.reasoning ? { content: streamOutput.reasoning } : undefined;+ return streamOutput.thinkingContent ? { content: streamOutput.thinkingContent } : undefined;};const sanitizePersistedTools = (toolsCalling: ChatToolPayload[]) =>@@ -204,7 +204,7 @@ export const persistInterruptedServerCallLlmResult = async ({streamOutput,toolsCalling,}: PersistInterruptedServerCallLlmResultInput): Promise<void> => {- if (!streamOutput.content && !streamOutput.reasoning && toolsCalling.length === 0) return;+ if (!streamOutput.content && !streamOutput.thinkingContent && toolsCalling.length === 0) return;try {await messageModel.update(assistantMessageId, {@@ -214,14 +214,16 @@ export const persistInterruptedServerCallLlmResult = async ({currentStepUsage,interruptedMidStream: true,}),- reasoning: streamOutput.reasoning ? { content: streamOutput.reasoning } : undefined,+ reasoning: streamOutput.thinkingContent+ ? { content: streamOutput.thinkingContent }+ : undefined,tools: sanitizePersistedTools(toolsCalling),});log('[%s] Interrupted finalize: persisted partial content (c=%d r=%d tools=%d)',operationLogId,streamOutput.content.length,- streamOutput.reasoning.length,+ streamOutput.thinkingContent.length,toolsCalling.length,);} catch (error) {diff --git a/packages/agent-runtime/src/transport/llm.ts b/packages/agent-runtime/src/transport/llm.tsindex 66b6c8ae16c..e5308007af2 100644--- a/packages/agent-runtime/src/transport/llm.ts+++ b/packages/agent-runtime/src/transport/llm.ts@@ -54,9 +54,10 @@ export interface LLMAttemptOutput {hasContentImages: boolean;hasReasoningImages: boolean;imageList: ChatImageItem[];- reasoning: string;reasoningParts: LLMAttemptContentPart[];speed?: ModelPerformance;+ /** Raw streamed thinking text; finalization converts it to the message reasoning object. */+ thinkingContent: string;toolCalls: MessageToolCall[];toolsCalling: ChatToolPayload[];usage?: ModelUsage;