From 0082e1ec9727be2f39b5a5264cc37eecb93edbe3 Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Wed, 18 Mar 2026 19:20:31 +0000 Subject: [PATCH] Fix issue where subagent thoughts are appended. (#22975) --- packages/core/src/agents/local-invocation.test.ts | 12 +++++++++--- packages/core/src/agents/local-invocation.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/src/agents/local-invocation.test.ts b/packages/core/src/agents/local-invocation.test.ts index 0cd77176ba..39c3ea1fe5 100644 --- a/packages/core/src/agents/local-invocation.test.ts +++ b/packages/core/src/agents/local-invocation.test.ts @@ -230,7 +230,7 @@ describe('LocalSubagentInvocation', () => { expect(display.terminateReason).toBe(AgentTerminateMode.TIMEOUT); }); - it('should stream THOUGHT_CHUNK activities from the executor', async () => { + it('should stream THOUGHT_CHUNK activities from the executor, replacing the last running thought', async () => { mockExecutorInstance.run.mockImplementation(async () => { const onActivity = MockLocalAgentExecutor.create.mock.calls[0][2]; @@ -245,7 +245,7 @@ describe('LocalSubagentInvocation', () => { isSubagentActivityEvent: true, agentName: 'MockAgent', type: 'THOUGHT_CHUNK', - data: { text: ' Still thinking.' }, + data: { text: 'Thinking about next steps.' }, } as SubagentActivityEvent); } return { result: 'Done', terminate_reason: AgentTerminateMode.GOAL }; @@ -258,7 +258,13 @@ describe('LocalSubagentInvocation', () => { expect(lastCall.recentActivity).toContainEqual( expect.objectContaining({ type: 'thought', - content: 'Analyzing... Still thinking.', + content: 'Thinking about next steps.', + }), + ); + expect(lastCall.recentActivity).not.toContainEqual( + expect.objectContaining({ + type: 'thought', + content: 'Analyzing...', }), ); }); diff --git a/packages/core/src/agents/local-invocation.ts b/packages/core/src/agents/local-invocation.ts index 142a0bc518..f78faf32c0 100644 --- a/packages/core/src/agents/local-invocation.ts +++ b/packages/core/src/agents/local-invocation.ts @@ -120,7 +120,7 @@ export class LocalSubagentInvocation extends BaseToolInvocation< lastItem.type === 'thought' && lastItem.status === 'running' ) { - lastItem.content += text; + lastItem.content = text; } else { recentActivity.push({ id: randomUUID(),