Please help: AI Agent - Cannot read properties of undefined (reading 'map')

The first time I ran this workfow, it just went fine but now- without obvious reason - it doesn’t work anymore.

Error Details:

Node type

@n8n/n8n-nodes-langchain.agent

Node version

2.1 (Latest version: 2.2)

n8n version

1.103.2 (Cloud)

Time

25.7.2025, 12:40:23

Stack trace

NodeOperationError: Cannot read properties of undefined (reading 'map') at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5dabdc5b9e72a2f1cc0986522789e88b/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V2/execute.ts:305:12 at Array.forEach (<anonymous>) at ExecuteContext.toolsAgentExecute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5dabdc5b9e72a2f1cc0986522789e88b/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/V2/execute.ts:294:16) at processTicksAndRejections (node:internal/process/task_queues:105:5) at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+n8n-nodes-langchain@file+packages+@n8n+nodes-langchain_5dabdc5b9e72a2f1cc0986522789e88b/node_modules/@n8n/n8n-nodes-langchain/nodes/agents/Agent/V2/AgentV2.node.ts:117:10) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1211:9) at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1581:27 at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2157:11

Workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version: cloudhosted N8N

If you need any more information, please don’t hesitate to ask :slight_smile:

Thank you very much for your help!

Hi Robert,

I ran into the same issue, and after some digging, I found the cause and a workaround.

The error is due to a malformed message in the chat history — specifically, a record like this:

{
  "type": "human",
  "additional_kwargs": {},
  "response_metadata": {}
}

This entry is missing a content field, and when the AI Agent node tries to read it, it throws the Cannot read properties of undefined (reading 'map') error.

To fix it, I wrote an SQL statement that removes these problematic entries from the n8n_chat_histories table:

Just replace 'YOUR_SESSION_ID' with the actual session ID where the issue occurs. After running this and re-executing the AI Agent node, everything worked fine again.

If you’re going to use it like my image, make sure you enable the workflow timeout, so you don’t end up in an infinite loop if that’s not the problem.

Hope this helps! Let me know if you need any further details.

2 Likes

Thanks Ken! This solved my problem.

2 Likes

Hi Ken, can you help me how to create a agent node with 2 output Success and Error. Tks

In the Settings tab of the agent, under the On Error option, you can choose “Continue (using error output)”.
That way, your agent node will have two possible outputs: Success and Error.

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