Subject: AI Agent Error: Cannot read properties of undefined (reading 'reduce') in ToolsAgent/executeBatch.ts

Describe the problem/error/question

The Problem
I am experiencing a recurring, seemingly random crash in my WhatsApp Restaurant AI Agent. The workflow can handle complex orders smoothly (multiple turns, tool calls), but then randomly crashes on simple messages like “Ok” or “Okay,” or sometimes even on the very first message of a conversation.

{
“errorMessage”: “Cannot read properties of undefined (reading ‘reduce’)”,
“nodeName”: “RESTAURANT ASSISTANT”,
“nodeType”: “@n8n/n8n-nodes-langchain.agent”,
“stackTrace”: [
“NodeOperationError: Cannot read properties of undefined (reading ‘reduce’)”,
“at …/ToolsAgent/V3/helpers/executeBatch.ts:88:11”,
“at executeBatch (…/ToolsAgent/V3/helpers/executeBatch.ts:77:15)”
]
}

My Environment

  • n8n Version: 1.123.4 (Self Hosted)

  • Deployment: Docker / npm (Standard installation)

  • Agent Type: Tools Agent (V3)

  • Memory: Simple Memory (Context Window: 5)

  • LLM: [Gemini 2.5 flash]

  • Trigger: WhatsApp (Webhook)

(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:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Thoth_AI From my POV everything seems fine with your workflow and nothing looks wrong with it. It almost perfectly align with Tools Agent v3 bug.

The stack trace gives it away. The crash occurs on .reduce in ToolsAgent/V3/helpers/executeBatch.ts. This means that the agent sometimes ends up with an internal structure that’s undefined. That typically happens with a short or empty-style input, like “Ok” or the first message, not when more complex. The agent deals well with the tough challenges but stumbles when it comes to edge cases.

There was a similar pattern detected previously related to Tools Agent v3, particularly when tools and memory involved. Some LLMs trigger it more frequently than others, indicating high model sensitivity.

It seems the most reliable fix people have found is simply switching back to v2.2 (or any v2.x) on the AI Agent node and reconnecting the same tools and same memory. The v2 version is less offensive and does not explode on the edge cases.

If you absolutely insist on sticking with v3, you might want to try changing the model to something other than Gemini 2.5 Flash something like GPT or a model from Anthropic and see if the crashes stop or not. In some cases, it has been observed that swapping model alone instantly fixes random tool-agent failures.

Somethings you could do : Tweak the system prompt a bit (because sometimes a large system prompt increases the chances of hallucination), use GPT 4.1 that has a context window of 1 million tokens, or something like Claude 3.5 or 4.5 sonnet. (I personally use these)

I hope this breakdown helps, Happy to share more if you need @Thoth_AI

Thanks for the feedback. Will implement your suggestions and get back here hopefully

1 Like

Hi @Thoth_AI Just upgrade your n8n to the latest version, as AI agent got a lot better in v2+ so please consider upgrading your n8n version, hope this helps.

1 Like

Thanks very much.

Glad it helped, kindly mark that as a solution! Cheers!

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