From bbcfb5ab631341cc8f944f91a0791edd480bf4ec Mon Sep 17 00:00:00 2001 From: corentin-hoareau <174796471+corentin-hoareau@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:08:59 +0200 Subject: [PATCH] Fixes state interpolation when using {{ output }} (#5039) * Fixes the lossy-replace when a new state assignment contains the {{ output }} variable * Replaces replace with replaceAll --------- Co-authored-by: Corentin --- packages/components/nodes/agentflow/Agent/Agent.ts | 2 +- .../components/nodes/agentflow/CustomFunction/CustomFunction.ts | 2 +- packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts | 2 +- packages/components/nodes/agentflow/Retriever/Retriever.ts | 2 +- packages/components/nodes/agentflow/Tool/Tool.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/components/nodes/agentflow/Agent/Agent.ts b/packages/components/nodes/agentflow/Agent/Agent.ts index 035b1a718..09177cbce 100644 --- a/packages/components/nodes/agentflow/Agent/Agent.ts +++ b/packages/components/nodes/agentflow/Agent/Agent.ts @@ -1081,7 +1081,7 @@ class Agent_Agentflow implements INode { if (newState && Object.keys(newState).length > 0) { for (const key in newState) { if (newState[key].toString().includes('{{ output }}')) { - newState[key] = finalResponse + newState[key] = newState[key].replaceAll('{{ output }}', finalResponse) } } } diff --git a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts index 8f31c0143..3bdc60681 100644 --- a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts @@ -194,7 +194,7 @@ class CustomFunction_Agentflow implements INode { if (newState && Object.keys(newState).length > 0) { for (const key in newState) { if (newState[key].toString().includes('{{ output }}')) { - newState[key] = finalOutput + newState[key] = newState[key].replaceAll('{{ output }}', finalOutput) } } } diff --git a/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts b/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts index ebb5ac36f..492c00af1 100644 --- a/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts +++ b/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts @@ -225,7 +225,7 @@ class ExecuteFlow_Agentflow implements INode { if (newState && Object.keys(newState).length > 0) { for (const key in newState) { if (newState[key].toString().includes('{{ output }}')) { - newState[key] = resultText + newState[key] = newState[key].replaceAll('{{ output }}', resultText) } } } diff --git a/packages/components/nodes/agentflow/Retriever/Retriever.ts b/packages/components/nodes/agentflow/Retriever/Retriever.ts index 8524fcd12..b9af63b76 100644 --- a/packages/components/nodes/agentflow/Retriever/Retriever.ts +++ b/packages/components/nodes/agentflow/Retriever/Retriever.ts @@ -201,7 +201,7 @@ class Retriever_Agentflow implements INode { if (newState && Object.keys(newState).length > 0) { for (const key in newState) { if (newState[key].toString().includes('{{ output }}')) { - newState[key] = finalOutput + newState[key] = newState[key].replaceAll('{{ output }}', finalOutput) } } } diff --git a/packages/components/nodes/agentflow/Tool/Tool.ts b/packages/components/nodes/agentflow/Tool/Tool.ts index be6c639a8..59b81f553 100644 --- a/packages/components/nodes/agentflow/Tool/Tool.ts +++ b/packages/components/nodes/agentflow/Tool/Tool.ts @@ -334,7 +334,7 @@ class Tool_Agentflow implements INode { if (newState && Object.keys(newState).length > 0) { for (const key in newState) { if (newState[key].toString().includes('{{ output }}')) { - newState[key] = toolOutput + newState[key] = newState[key].replaceAll('{{ output }}', toolOutput) } } }