Trouble Returning Full List of Loop Outputs in Agent Builder

Hi everyone!

I’m building an agent that evaluates AI recommendations for multiple clients from a .txt file. I use a while loop to process each client and append each loop’s output to a result list using a Set State node inside the while loop:

assign value:
type(state.result) == "list" 
  ? state.result + [state.current_output] 
  : [state.current_output]

to variable:
result []

The problem: in the end node, I can’t return the full list. It either comes back empty or only the last item.

Has anyone managed to accumulate outputs from a while loop in state.result and return the full list? Any tips or examples would help!

Thanks!

I hit the same behavior where only the last value survived. In my case, the issue was that each loop iteration reset the node graph’s scope, so the state assignment wasn’t actually cumulative. Once I initialized the result list outside the loop and made sure the Set State node didn’t create a new object each cycle, the outputs started stacking correctly. The agent builder doesn’t always keep state mutations intuitive, so it took a bit of trial and error to make it stable.