I am facing an issue with n8n’s persistent chat memory nodes and OpenAI tool calling, and I am completely stuck on how to resolve it for a production environment.
The Context & Version Change
- Previous n8n Version: 2.11.3 (Everything worked perfectly)
- Current n8n Version: 2.30.0 (The issue appeared immediately after upgrading to this version)
- LLM Node: Azure OpenAI Chat Model (gpt-4o) connected to an AI Agent node with several custom HTTP Request tools.
What I have already tried to debug:
- The Database Switch: Originally, I was using MongoDB Chat Memory when this started happening. I recently migrated the workflow completely over to a freshly configured Postgres Chat Memory instance. The exact same crash still happens.
- Fresh Sessions: If I change the Session ID to a brand-new string or try a different user account completely, the first turn works, but it breaks again 2-3 conversations later.
- The Quick Fix (Simple Chat Memory): As a temporary workaround, I swapped out the persistent databases and used the built-in Simple Chat Memory node. When using Simple Chat Memory, the workflow runs perfectly without ever throwing this error.
Since Simple Chat Memory stores conversations in active RAM, I cannot use it for our production environment where persistent chat histories are mandatory. It seems like the persistent memory nodes (MongoDB/Postgres) are saving or retrieving the LangChain tool message array format incorrectly, truncating it, or dropping the critical tool_call_id metadata needed by OpenAI on subsequent turns.
Any help or structural workarounds would be highly appreciated!
Error message
Bad request - please check your parameters. Invalid parameter: messages with role ‘tool’ must be a response to a preceding message with ‘tool_calls’.
Information on your n8n setup
- n8n version: 2.30.0 (self hosted)
- Database (default: SQLite): yes
- Running n8n via (Docker, npm, n8n cloud, desktop app): Docker