@@ -335,6 +335,30 @@ export const resolveVariables = async (
335
335
}
336
336
}
337
337
338
+ // Check if the variable is an output reference like `nodeId.output.path`
339
+ const outputMatch = variableFullPath . match ( / ^ ( .* ?) \. o u t p u t \. ( .+ ) $ / )
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
+
338
362
// Find node data in executed data
339
363
// sometimes turndown value returns a backslash like `llmAgentflow\_1`, remove the backslash
340
364
const cleanNodeId = variableFullPath . replace ( '\\' , '' )
0 commit comments