It seems to me like you might want to add a validation.
You can perform this by checking if the variable is defined and is an array before calling .map()
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.
For local chat, this often happens for me when changing from a standard AI model to a thinking AI model. This changes a json.output to an array, and if returning the output to chat history, the array winds up in the chat history rather than the regular output.
Fix: On local chat history (not PostGres or other), just increment the name to start a new chat. ie. Chat1 to Chat2.
I handle actual history through a memory database, and only a local chat for local context, so this usually does not impact anything for me (not serving chat to hundreds of users, just myself on the backend).
I am having the same issue, it is so frustrating that it works for my Enquiry Agent. However, it sometimes works and sometimes doesn’t work for the Booking Agent. Can anyone please help?
Hey, to anyone still having this issue with postgres chat memory nodes, modifying the table where the records are being store, allowing nulls on the jsonb field fixed it for me