From 2121e2db4e2599133ff3d0f1152ce7d02efcb760 Mon Sep 17 00:00:00 2001 From: eneaxharau Date: Tue, 30 Dec 2025 13:18:04 +0100 Subject: [PATCH] fix: prevent message duplication in analysis refinement Updated the refineAnalysis function to return only new messages, eliminating duplication caused by the previous implementation that appended all messages to the state. This change ensures cleaner state management in the reducer. --- src/agents/execution/agent-internal-graph.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/agents/execution/agent-internal-graph.ts b/src/agents/execution/agent-internal-graph.ts index a5a882c..a9e70df 100644 --- a/src/agents/execution/agent-internal-graph.ts +++ b/src/agents/execution/agent-internal-graph.ts @@ -177,10 +177,12 @@ async function refineAnalysis( const response = (await model.invoke(messages)) as any; const tokenUsage = extractTokenUsage(response); + // Return only the NEW messages - the reducer will append them to state.messages + // Previously this was [...state.messages, user, assistant] which caused duplication + // because the reducer does [...oldState, ...update] return { currentAnalysis: response, messages: [ - ...state.messages, { role: 'user', content: refinementPrompt }, { role: 'assistant', content: response.content }, ] as any,