I have a flow with 2 AI agents. One agent produces some data. Another agent uses that output and some tools to produce a decision whether to go back to the first agent. The second agent outputs a reason for the loop that I want to pass to the first agent. I have everything working with an if statement at the end, but I cannot figure out how to get the output back to the original agent. How can I make that happen?
Can you please share your workflow with us?
You can copy and paste it inside a code block.
To create a code block you just have to click here:
Your workflow will show up like this:
.
But trying to already answer your question, you can do something like this:
OK, here is an example of what I’m to do. The final output should be a concatenation of all the work done in the loops.
I see two options:
Static data
You can use workflow static data to “remember” values between iterations. In a Function node, for example, you can do something like this:
// Retrieve the global static data object
const staticData = this.getWorkflowStaticData('global');
// Initialize an array (or string) if it doesn't exist yet
if (!staticData.results) {
staticData.results = [];
}
// Push the current value (adjust property as needed)
staticData.results.push($json.value);
// Continue with the current execution (or return if necessary)
return items;
Then, once your loop ends, you can access the accumulated values from staticData.results. This works because static data persists across node executions within the same workflow run, letting you aggregate results just like the Done branch of a loop node would.
Use a loop node
The loop node has a “Done” branch that aggregates all outputs in separate items.
You could then use a formula to get all items or the “Aggregate” node to join everything in a single array.
The problem is you don’t have a number of items to run through, and I think the loop node needs it.
But it’s worth the shot. Let me know how it goes!
If my reply answers your question please remember to mark it as the solution
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.