AI Agent Tool Referencing only the first variable although multiple input items are given

Describe the problem/error/question

Hi everyone, this might be a very noobie situation, but I hope I can get some help.

In simple terms, my workflow expects emails, triggered by an outlook trigger node, and then an AI Agent node generates and answer email. When dealing with single emails, everything works as expected. However, after doing some active workflow testing, I have found out that multiple emails might enter the workflow at the same time (of course it is good since you can avoid workflow executions). I initially expected everything to work correctly, but I had first() used multiple times in different nodes, meaning that the workflow would break whenever multiple emails entered it at the same time. I fixed most of this by using .item and referencing variables from other nodes but, for my postgress tool used as the memory for the agent, although I reference a set node containing multiple IDs (I use this as the DB id to match email conversations) for every AI agent execution, it only uses a single ID, kind of the same behavior as if you were to use first(). This causes a mix of information from multiple emails to a single one only.

From the image above, you can see that my set node contains two IDs, one for email 1 and another one for email 2.

When referencing the same set node, using .item, it is only using the ID from item 0 in both iterations from the AI Agent (One for each email) rather than each corresponding id for each iteration. Am I doing a stupid mistake? Is this a bug? Am I not understanding properly how items and variables are matched in n8n? I can’t seem to figure out the cause of this issue.

Information on your n8n setup

  • **n8n version:1.98.1
  • Database PostGres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via ( n8n cloud):
  • Operating system: Windows 10

hey @Dimi259 ,

is it possible for you to share your workflow here.

Insert your workflow by clicking ‘</>’ and pasting in [the workflow’s code]

or screenshot, I would love to have a look at your workflow before proposing the solution.

Thanks : )

Hi @Sudhanshu_Sharma
Here is a screenshot of my workflow.

Hey @Dimi259,

I had a look at your screenshots, but it’s hard to pinpoint the exact issue without seeing how the expressions and data are flowing through the workflow.

I thought about asking for the workflow JSON, but even that might not be enough to debug this properly.

If you’re okay with it, we can jump on a quick Google Meet… I’ll do my best to help you out.

Just DM me and I’ll share the link with you :slightly_smiling_face:

We connected on Google Meet, and found the solution.

In order to make it work, we simply put the agent node inside the loop and it worked.

@Dimi259 Please share the screenshot of the updated workflow here.

That’s it , one more problem get solved. :slight_smile:

1 Like

Thanks to Sudhanshu, the issue has been resolved. Sometimes what seems too simple is actually the best solution…

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.