File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
components/nodes/agentflow/Iteration Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,25 @@ class Iteration_Agentflow implements INode {
3232 description : 'The input array to iterate over' ,
3333 acceptVariable : true ,
3434 rows : 4
35+ } ,
36+ {
37+ label : 'Output Structure' ,
38+ name : 'iterationOutputStructure' ,
39+ type : 'options' ,
40+ description : 'How to structure the output from all iterations' ,
41+ options : [
42+ {
43+ label : 'Aggregated Text' ,
44+ name : 'aggregatedText' ,
45+ description : 'Join all iteration outputs into a single text separated by newlines'
46+ } ,
47+ {
48+ label : 'JSON Array' ,
49+ name : 'jsonArray' ,
50+ description : 'Preserve the input array structure — output[i] corresponds to the result of processing input[i]'
51+ }
52+ ] ,
53+ default : 'aggregatedText'
3554 }
3655 ]
3756 }
@@ -56,13 +75,15 @@ class Iteration_Agentflow implements INode {
5675 throw new Error ( 'Invalid input array' )
5776 }
5877
78+ const iterationOutputStructure = nodeData . inputs ?. iterationOutputStructure ?? 'aggregatedText'
5979 const state = options . agentflowRuntime ?. state as ICommonObject
6080
6181 const returnOutput = {
6282 id : nodeData . id ,
6383 name : this . name ,
6484 input : {
65- iterationInput : iterationInputArray
85+ iterationInput : iterationInputArray ,
86+ iterationOutputStructure
6687 } ,
6788 output : { } ,
6889 state
Original file line number Diff line number Diff line change @@ -1243,6 +1243,7 @@ const executeNode = async ({
12431243 }
12441244
12451245 // Initialize array to collect results from iterations
1246+ const outputStructure = results . input ?. iterationOutputStructure ?? 'aggregatedText'
12461247 const iterationResults : string [ ] = [ ]
12471248
12481249 // Execute sub-flow for each item in the iteration array
@@ -1289,9 +1290,12 @@ const executeNode = async ({
12891290 productId
12901291 } )
12911292
1292- // Store the result
1293+ // Store the result.
1294+ // In jsonArray mode, always push to maintain 1:1 mapping with the input array.
12931295 if ( subFlowResult ?. text ) {
12941296 iterationResults . push ( subFlowResult . text )
1297+ } else if ( outputStructure === 'jsonArray' ) {
1298+ iterationResults . push ( '' )
12951299 }
12961300
12971301 // Add executed data from sub-flow to main execution data with appropriate iteration context
@@ -1351,7 +1355,7 @@ const executeNode = async ({
13511355 results . output = {
13521356 ...( results . output || { } ) ,
13531357 iterationResults,
1354- content : iterationResults . join ( '\n' )
1358+ content : outputStructure === 'jsonArray' ? JSON . stringify ( iterationResults ) : iterationResults . join ( '\n' )
13551359 }
13561360
13571361 logger . debug ( ` 📊 Completed all iterations. Total results: ${ iterationResults . length } ` )
You can’t perform that action at this time.
0 commit comments