n8n - 💡(How to fix) Fix AI Agent with nested AgentToolV3 + Redis Memory sends invalid OpenAI tool messages in n8n 2.25.1

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

The error is: The issue appears after some successful interactions. If I clear Redis memory, the workflow works again for a while, but the same error eventually returns. However, instead of the older error: I now get an OpenAI request validation error about invalid role: tool message ordering. It looks like the message history sent to OpenAI may contain a tool message without the immediately preceding assistant message containing matching tool_calls. 6. After some successful runs, the workflow intermittently fails with the OpenAI invalid parameter error. Result: clearing Redis memory fixes the issue temporarily, but the error returns after more interactions. 8. After more interactions, the same error returns again.

  • error: all
  • Clearing Redis Chat Memory temporarily fixes the issue, but the error returns after more conversational turns.

Fix Action

Fix / Workaround

Workarounds Tried

Code Example

Bad request - please check your parameters
Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.

---

langchain agent Node: Resolve sub-agent tool calls inline when nested (#31072)

---

Parent AI Agent
  -> AgentToolV3 sub-agent
      -> toolWorkflow / Redis / other tools

---

Parent AI Agent
  -> AgentToolV3: Agente Videos de Consejos
      -> AgentToolV3: Agente Guionista Videos Cortos
          -> tools

---

The Tool attempted to return an engine request, which is not supported in Agents

---

assistant with tool_calls
tool response with matching tool_call_id
assistant final answer

---

Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.

---

Bad request - please check your parameters
Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.

---

assistant message with tool_calls
tool response with matching tool_call_id
assistant final response

---

Parent AI Agent
  -> AgentToolV3 sub-agent
      -> toolWorkflow / Redis / other tools

---

Parent AI Agent
  -> AgentToolV3 sub-agent
      -> another AgentToolV3 sub-agent
          -> tools
RAW_BUFFERClick to expand / collapse

Bug Description

Bug Description

After upgrading from n8n 2.23.0 to 2.25.1, my production workflow started intermittently failing in an AI Agent setup that uses nested AgentToolV3 sub-agents and Redis Chat Memory.

The error is:

Bad request - please check your parameters
Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.

The issue appears after some successful interactions. If I clear Redis memory, the workflow works again for a while, but the same error eventually returns.

Why this may be related to #30773 / #31072

I saw that 2.25.1 includes:

langchain agent Node: Resolve sub-agent tool calls inline when nested (#31072)

My workflow has a similar nested architecture:

Parent AI Agent
  -> AgentToolV3 sub-agent
      -> toolWorkflow / Redis / other tools

There is also one deeper nested chain:

Parent AI Agent
  -> AgentToolV3: Agente Videos de Consejos
      -> AgentToolV3: Agente Guionista Videos Cortos
          -> tools

However, instead of the older error:

The Tool attempted to return an engine request, which is not supported in Agents

I now get an OpenAI request validation error about invalid role: tool message ordering. It looks like the message history sent to OpenAI may contain a tool message without the immediately preceding assistant message containing matching tool_calls.

Expected behavior

Nested AgentToolV3 chains should complete the internal tool-call loop and return a valid final answer to the parent AI Agent.

The OpenAI message history should always preserve valid ordering:

assistant with tool_calls
tool response with matching tool_call_id
assistant final answer

Actual behavior

After some interactions, the AI Agent sends an invalid OpenAI message history and fails with:

Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.

Clearing Redis Chat Memory temporarily fixes the issue, but it returns later.

Steps to Reproduce

  1. Create a parent AI Agent node.
  2. Connect one or more AgentToolV3 nodes as tools to the parent agent.
  3. Inside at least one sub-agent, connect additional tools such as toolWorkflow, Redis, or another AgentToolV3.
  4. Enable Redis Chat Memory on the parent agent and/or sub-agents.
  5. Use the workflow for multiple conversational turns where the parent agent delegates to sub-agents and sub-agents call tools.
  6. After some successful runs, the workflow intermittently fails with the OpenAI invalid parameter error.

Workarounds Tried

  • Disabled Use Responses API on the AI model.
  • Cleared Redis Chat Memory.
  • Re-ran the workflow.

Result: clearing Redis memory fixes the issue temporarily, but the error returns after more interactions.

Environment

  • n8n version: 2.25.1
  • Deployment: self-hosted
  • Workflow type: production Telegram bot workflow
  • Main node: AI Agent v3.1
  • Sub-agent nodes: @n8n/n8n-nodes-langchain.agentTool, typeVersion 3
  • Memory: Redis Chat Memory
  • OpenAI model node with Use Responses API disabled
  • Regression: this did not happen for me on 2.23.0; it started after upgrading to 2.25.1

Additional context

This may be a regression or incomplete edge case after #31072, specifically when nested AgentToolV3 calls interact with Redis Chat Memory and persisted conversation history.

I can provide a sanitized workflow JSON and screenshots of the failing execution if needed.

<img width="1127" height="452" alt="Image" src="https://github.com/user-attachments/assets/0cdd556a-ec98-423a-b430-7aa8e93f0c04" /> <img width="1280" height="495" alt="Image" src="https://github.com/user-attachments/assets/2f8a6221-ba7e-4eb9-8873-6995ff3f86f2" /> <img width="1267" height="532" alt="Image" src="https://github.com/user-attachments/assets/9d993a7f-1642-4124-8080-8a0dec208dbe" /> <img width="645" height="741" alt="Image" src="https://github.com/user-attachments/assets/a7b684e1-fde1-4149-95f6-d21d2a63e9c7" />

To Reproduce

  1. Create a workflow with a parent AI Agent node.
  2. Connect several AgentToolV3 nodes as sub-agents/tools to the parent AI Agent.
  3. Inside at least one sub-agent, connect additional tools such as toolWorkflow, Redis tools, or another AgentToolV3.
  4. Enable Redis Chat Memory on the parent AI Agent and/or on the sub-agents.
  5. Use the workflow for multiple conversational turns where the parent agent delegates work to sub-agents and the sub-agents call their own tools.
  6. The workflow works for some interactions, but eventually fails with:
Bad request - please check your parameters
Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.
  1. Clearing Redis Chat Memory temporarily fixes the issue.
  2. After more interactions, the same error returns again.

Expected behavior

The parent AI Agent should be able to call nested AgentToolV3 sub-agents, and those sub-agents should be able to call their own tools without corrupting the OpenAI message history.

The OpenAI message sequence should always remain valid, including after multiple conversational turns and when Redis Chat Memory is enabled.

Expected valid ordering:

assistant message with tool_calls
tool response with matching tool_call_id
assistant final response

The workflow should never send a role: tool message to OpenAI unless it is directly responding to a previous assistant message with matching tool_calls.

The nested agent/tool chain should complete and return a normal final response to the parent AI Agent, instead of failing with an invalid OpenAI request.

Debug Info

core

  • n8nVersion: 2.25.1
  • platform: docker (self-hosted)
  • nodeJsVersion: 24.15.0
  • nodeEnv: production
  • database: postgres
  • executionMode: regular
  • concurrency: -1
  • license: enterprise (production)

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 504 hours
  • maxCount: 10000 executions

client

  • userAgent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/148.0.0.0 safari/537.36
  • isTouchDevice: false

Generated at: 2026-06-05T20:46:32.615Z

Additional context

  • This started after upgrading from n8n 2.23.0 to 2.25.1.
  • The workflow is a production Telegram bot workflow.
  • Main node: AI Agent, typeVersion: 3.1.
  • Sub-agent nodes: @n8n/n8n-nodes-langchain.agentTool, typeVersion: 3.
  • Several sub-agents call internal toolWorkflow tools.
  • Redis Chat Memory is enabled.
  • Use Responses API is disabled on the OpenAI model.
  • Clearing Redis Chat Memory temporarily fixes the issue, but the error returns after more conversational turns.
  • The workflow has a nested structure similar to:
Parent AI Agent
  -> AgentToolV3 sub-agent
      -> toolWorkflow / Redis / other tools

and in one case:

Parent AI Agent
  -> AgentToolV3 sub-agent
      -> another AgentToolV3 sub-agent
          -> tools

This may be a remaining edge case or regression related to nested AgentToolV3 calls, Redis Chat Memory, and persisted OpenAI tool-call message history.

Operating System

Docker self-hosted. Host OS unknown / can provide if needed.

n8n Version

2.25.1

Node.js Version

24.15.0

Database

PostgreSQL

Execution mode

main (default)

Hosting

self hosted

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The parent AI Agent should be able to call nested AgentToolV3 sub-agents, and those sub-agents should be able to call their own tools without corrupting the OpenAI message history.

The OpenAI message sequence should always remain valid, including after multiple conversational turns and when Redis Chat Memory is enabled.

Expected valid ordering:

assistant message with tool_calls
tool response with matching tool_call_id
assistant final response

The workflow should never send a role: tool message to OpenAI unless it is directly responding to a previous assistant message with matching tool_calls.

The nested agent/tool chain should complete and return a normal final response to the parent AI Agent, instead of failing with an invalid OpenAI request.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING