Skip to content

Commit 27bc47e

Browse files
authored
Feature: Add dot notation support for nested output variable resolution (#4506)
Add dot notation support for nested output variable resolution
1 parent da8d0f1 commit 27bc47e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/server/src/utils/buildAgentflow.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,30 @@ export const resolveVariables = async (
335335
}
336336
}
337337

338+
// Check if the variable is an output reference like `nodeId.output.path`
339+
const outputMatch = variableFullPath.match(/^(.*?)\.output\.(.+)$/)
340+
if (outputMatch && agentFlowExecutedData) {
341+
// Extract nodeId and outputPath from the match
342+
const [, nodeIdPart, outputPath] = outputMatch
343+
// Clean nodeId (handle escaped underscores)
344+
const cleanNodeId = nodeIdPart.replace('\\', '')
345+
// Find the last (most recent) matching node data instead of the first one
346+
const nodeData = [...agentFlowExecutedData].reverse().find((d) => d.nodeId === cleanNodeId)
347+
if (nodeData?.data?.output && outputPath.trim()) {
348+
const variableValue = get(nodeData.data.output, outputPath)
349+
if (variableValue !== undefined) {
350+
// Replace the reference with actual value
351+
const formattedValue =
352+
Array.isArray(variableValue) || (typeof variableValue === 'object' && variableValue !== null)
353+
? JSON.stringify(variableValue)
354+
: String(variableValue)
355+
resolvedValue = resolvedValue.replace(match, formattedValue)
356+
// Skip fallback logic
357+
continue
358+
}
359+
}
360+
}
361+
338362
// Find node data in executed data
339363
// sometimes turndown value returns a backslash like `llmAgentflow\_1`, remove the backslash
340364
const cleanNodeId = variableFullPath.replace('\\', '')

0 commit comments

Comments
 (0)