Problem in node ‘AI Agent‘ Cannot read properties of undefined (reading 'reduce')

Problem in node ‘AI Agent‘
Cannot read properties of undefined (reading ‘reduce’)

Describe the problem/error/question

I have node AI Agent.
The version of the node is the latest. AI Agent node version 3.1 (Latest
Randomly, sometimes I have an error instead of a normal text answer from the model. The error looks like this
“Problem in node ‘AI Agent‘
Cannot read properties of undefined (reading ‘reduce’)”
I have a very large context.
This error is not always (around 3 percent of teh times)
The retry on fail feature does not work.
Can anyone please help me with this bug)&&&7

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.4.3 self-hosted
  • Database (default: SQLite): mongo db ut it is separate. Only model node is connected to the AI Agent node
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system:

welcome to the n8n community @vika87
I’d trim the context before it reaches the AI Agent, make sure any optional inputs are never undefined, and update n8n to the latest version. In cases like this, the error is usually triggered by oversized context or inconsistent input structure rather than the model itself.

1 Like

we hit this with larger workflows too — the AI Agent tends to choke on context over a certain size. trimming down what you pass and making sure theres no undefined values (especially in tool outputs) should help. whats your actual context size roughly, like how many tokens is the input?

1 Like

Hi @vika87 Welcome!
Let me help you. First use GPT-5 models they got the best context window so that even your large data can be handled by those models, also use a good model provider if you are not using like Openrouter, and basically using a GOOD model would easily fix this problem so go with it.

1 Like