From 27bc47ed57ad38d762a18a8c7ef129276b805491 Mon Sep 17 00:00:00 2001 From: russelj1 Date: Wed, 28 May 2025 15:24:43 +0100 Subject: [PATCH] Feature: Add dot notation support for nested output variable resolution (#4506) Add dot notation support for nested output variable resolution --- packages/server/src/utils/buildAgentflow.ts | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/server/src/utils/buildAgentflow.ts b/packages/server/src/utils/buildAgentflow.ts index b503b145..4ce91285 100644 --- a/packages/server/src/utils/buildAgentflow.ts +++ b/packages/server/src/utils/buildAgentflow.ts @@ -335,6 +335,30 @@ export const resolveVariables = async ( } } + // Check if the variable is an output reference like `nodeId.output.path` + const outputMatch = variableFullPath.match(/^(.*?)\.output\.(.+)$/) + if (outputMatch && agentFlowExecutedData) { + // Extract nodeId and outputPath from the match + const [, nodeIdPart, outputPath] = outputMatch + // Clean nodeId (handle escaped underscores) + const cleanNodeId = nodeIdPart.replace('\\', '') + // Find the last (most recent) matching node data instead of the first one + const nodeData = [...agentFlowExecutedData].reverse().find((d) => d.nodeId === cleanNodeId) + if (nodeData?.data?.output && outputPath.trim()) { + const variableValue = get(nodeData.data.output, outputPath) + if (variableValue !== undefined) { + // Replace the reference with actual value + const formattedValue = + Array.isArray(variableValue) || (typeof variableValue === 'object' && variableValue !== null) + ? JSON.stringify(variableValue) + : String(variableValue) + resolvedValue = resolvedValue.replace(match, formattedValue) + // Skip fallback logic + continue + } + } + } + // Find node data in executed data // sometimes turndown value returns a backslash like `llmAgentflow\_1`, remove the backslash const cleanNodeId = variableFullPath.replace('\\', '')