Hi L.
The short answer is: Yes, you need the aggregator.
Now to the long answer.
Google Sheets Search Row module yields one bundle for each line found. These bundles are then iterated over as separate operations from the next module on. This would lead to “several returns” of your scenario, but that’s not possible.
From Help Center:
The Return output module always finishes the scenario run. It works similarly as the return statement in programming. You cannot add any subsequent modules after the Return output module in the current route.
Keep in mind that when using routers, a Return output module in a route finishes the scenario. The modules in the subsequent routes won’t run.
So, if you don’t aggregate the results, your scenario will only return the first row found.
Aggregate, them map the resulting array to an array-type scenario output.
There are other aspects of your question that I would like to address as well.
You don’t need the Iterator after the Google Sheets Search Row module, as the latter already yields one bundle for each line found, as explained above.
Also, is there any reason to set multiple variables during the execution of the scenario? Are you combining input data with data read from Google Sheets? If you’re not, you can simply map the values read to return arguments.
Lastly, you will find several answers talking about how AI Agents are great for handling semistructured or unstructured data. However, when you have structured data that lends itself to linear processing flows (that’s what make does), it’s better to deal with all the predictable situations inside your scenario and restrict the agent’s reasoning to a bare minimum.
What I mean here is that the more guardrails you can set for your Agent, the better it will perform. So, yes, spoon-feed it with just the necessary bits (pun intended).
Don’t just give it everything and hope it will handle it. It probably will, someday, not in the near future. Right now we have hallucinations and token usage to watch for.
I’m thinking about writing a blog post about this, since I find fetching data from AI agents to be an essential matter in automation.
Basically, this is the pattern I use in my scenarios:
- I search for an exact match (if possible).
- If not found, I search for a partial match (if possible).
- If not found OR if there was no filter to begin with, then I return everything.
Here is a screenshot of an example. My AI Agents use this scenario as a tool for searching for supplier info.
You can see that the only time when I don’t aggregate the results is exactly when there is only one result.
Then I instruct the agent to only call this scenario once and do all the processing in memory, because it will either return the best match(es) or everything.
Guilherme