From 47de40761f48243a86baa03b0cb16aaffb6d5f3d Mon Sep 17 00:00:00 2001 From: Ahmed Mostafa <41272326+AhmedMostafa16@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:37:15 +0300 Subject: [PATCH] Fix Agent node structured output not updating flow state variables (#5548) Fix Agent state processing for structured output Updated the Agent class to handle structured output by passing a JSON string instead of a markdown-wrapped response to the `processTemplateVariables` function. This change allows for proper nested property access and resolves string replacement issues with object coercion. --- packages/components/nodes/agentflow/Agent/Agent.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/components/nodes/agentflow/Agent/Agent.ts b/packages/components/nodes/agentflow/Agent/Agent.ts index fee7cda9..e8a4074a 100644 --- a/packages/components/nodes/agentflow/Agent/Agent.ts +++ b/packages/components/nodes/agentflow/Agent/Agent.ts @@ -1394,7 +1394,9 @@ class Agent_Agentflow implements INode { } // Process template variables in state - newState = processTemplateVariables(newState, finalResponse) + const outputForStateProcessing = + isStructuredOutput && typeof response === 'object' ? JSON.stringify(response, null, 2) : finalResponse + newState = processTemplateVariables(newState, outputForStateProcessing) /** * Remove the temporarily added image artifact messages before storing