From 70342a72ec89d8612758b769d05403f85aa4228c Mon Sep 17 00:00:00 2001 From: Corentin Date: Thu, 7 Aug 2025 14:21:52 +0200 Subject: [PATCH 1/2] Fixes the lossy-replace when a new state assignment contains the {{ output }} variable --- 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 849a2e3e591..04885258299 100644 --- a/packages/components/nodes/agentflow/Agent/Agent.ts +++ b/packages/components/nodes/agentflow/Agent/Agent.ts @@ -957,7 +957,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].replace('{{ output }}', finalResponse) } } } diff --git a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts index 6922c651bb5..bfde5ef9761 100644 --- a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts @@ -213,7 +213,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].replace('{{ output }}', finalOutput) } } } diff --git a/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts b/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts index 26e5df7b60e..6a73ee70560 100644 --- a/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts +++ b/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts @@ -217,7 +217,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].replace('{{ output }}', resultText) } } } diff --git a/packages/components/nodes/agentflow/Retriever/Retriever.ts b/packages/components/nodes/agentflow/Retriever/Retriever.ts index 68420484e12..993fe237054 100644 --- a/packages/components/nodes/agentflow/Retriever/Retriever.ts +++ b/packages/components/nodes/agentflow/Retriever/Retriever.ts @@ -200,7 +200,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].replace('{{ output }}', finalOutput) } } } diff --git a/packages/components/nodes/agentflow/Tool/Tool.ts b/packages/components/nodes/agentflow/Tool/Tool.ts index c3945ff3e36..10c83377465 100644 --- a/packages/components/nodes/agentflow/Tool/Tool.ts +++ b/packages/components/nodes/agentflow/Tool/Tool.ts @@ -275,7 +275,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].replace('{{ output }}', toolOutput) } } } From fbf6abf92e009d4dd53dc4d75c8ae99b8bcdb49a Mon Sep 17 00:00:00 2001 From: Corentin Date: Thu, 7 Aug 2025 14:29:00 +0200 Subject: [PATCH 2/2] Replaces replace with replaceAll --- 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 04885258299..11d4b780196 100644 --- a/packages/components/nodes/agentflow/Agent/Agent.ts +++ b/packages/components/nodes/agentflow/Agent/Agent.ts @@ -957,7 +957,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] = newState[key].replace('{{ output }}', 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 bfde5ef9761..97919af11b1 100644 --- a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts @@ -213,7 +213,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] = newState[key].replace('{{ output }}', 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 6a73ee70560..9913b437e29 100644 --- a/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts +++ b/packages/components/nodes/agentflow/ExecuteFlow/ExecuteFlow.ts @@ -217,7 +217,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] = newState[key].replace('{{ output }}', 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 993fe237054..4268fba0b9e 100644 --- a/packages/components/nodes/agentflow/Retriever/Retriever.ts +++ b/packages/components/nodes/agentflow/Retriever/Retriever.ts @@ -200,7 +200,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] = newState[key].replace('{{ output }}', 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 10c83377465..034885c9304 100644 --- a/packages/components/nodes/agentflow/Tool/Tool.ts +++ b/packages/components/nodes/agentflow/Tool/Tool.ts @@ -275,7 +275,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] = newState[key].replace('{{ output }}', toolOutput) + newState[key] = newState[key].replaceAll('{{ output }}', toolOutput) } } }