Integration Challenge: Cerebras with Tools Agent - Validation Errors & Hanging Executions

Hi all,

I’m hitting a wall integrating Cerebras (Qwen3) with the Tools Agent in n8n v1.123.4 (Self-hosted).

I am using the LangChain Code Node in “Supply Data” mode to initialize the model. I am facing a catch-22 situation where I cannot pass the Agent’s validation without breaking the connection.

The Configuration

I’m using the ChatOpenAI adapter pointing to https://api.cerebras.ai/v1. Here is my current code attempt:

const { ChatOpenAI } = require("@langchain/openai");

const model = new ChatOpenAI({
  // Using "gpt-4" name to try and pass n8n's internal validation
  modelName: "gpt-4", 
  openAIApiKey: "MY_API_KEY", 
  configuration: {
    baseURL: "https://api.cerebras.ai/v1",
  },
  // Anti-hanging settings
  streaming: false,
  streamUsage: false,
  modelKwargs: {
    // The real model I want to use
    model: "qwen-3-235b-a22b-instruct-2507",
    parallel_tool_calls: false, 
  }
});

// Using n8n native method to output
this.addOutputData('ai_languageModel', model);
return { ai_languageModel: model };

The Issue

  1. Scenario A (Real Model Name):
    If I use modelName: "qwen-3-235b...", the code runs, but the AI Agent node throws:

    NodeOperationError: Tools Agent requires Chat Model which supports Tools calling
    (It seems n8n whitelists “tool-capable” models by name).

  2. Scenario B (Bypassing Validation):
    If I use the code above (modelName: "gpt-4"), I pass the validation, but the execution hangs indefinitely (timeout). It seems masking the name causes a protocol mismatch that keeps the connection open.

What I’ve Tried (and failed)

  • Monkey Patching: Manually assigning model.bindTools = model.bind (Still throws validation error).
  • Class Extension: Extending ChatOpenAI class to define bindTools explicitly (Still throws validation error).
  • Config Tweaks: streaming: false, streamUsage: false, and tiktokenModelName: "gpt-4".

Question

Is there a known way to force the Tools Agent to accept a custom OpenAI-compatible model name without triggering the Tools Agent requires Chat Model which supports Tools calling error?

Any help will be appreciatted!

Hello @ldaniel-jmz

You can use the Cerebras endpoint as an OpenAI-compatible API, it should work with a normal AI agent, I guess..

Now, regarding your question: I just want to share this very informative and useful video that includes a fully working LangChain Code Nodes, which I used for testing..

I hope it provides some helpful context for the issue you’re facing..

2 Likes

You were spot on. I had actually tried the OpenAI node before, but it kept hanging, so I assumed it wasn’t compatible.

It turns out the culprit was the “Use Responses API” toggle. I had it ON, and that breaks the connection with Cerebras. Turning it OFF fixed everything immediately. Thanks for the nudge!

UPDATE: Premature Solution - The Native Node Workaround is Unstable.
I am unmarking the solution because, after further testing, the native OpenAI node workaround (disabling “Use Responses API”) fails in multi-turn conversations.
The Issue:

  1. Turn 1: The model works fine, calls the tool, and n8n executes it.
  2. Turn 2 (Follow-up): When n8n sends the chat history back to Cerebras (Qwen) via the generic OpenAI node, the formatting of the previous tool results confuses the model.
  3. Result: Instead of triggering a new tool call, the model hallucinates raw text mimicking the tool execution log (e.g., printing JSON or “Used Tools…” text) but never actually triggering the n8n Agent execution logic.
    Conclusion:
    Connecting Cerebras directly via the generic OpenAI node causes a protocol mismatch in how chat history is handled. It seems the only robust way to handle multi-turn tool agents with Cerebras is using a dedicated driver (like langchain-cerebras) or a middleware that normalizes history (like OpenRouter), as the native n8n node allows “format leakage” that breaks the Qwen model’s reasoning loop.

SOLVED: The real culprit is AI Agent Version 3

After extensive testing, I found the root cause. It wasn’t the API configuration, it was the Agent version.

If you are using Cerebras (or other OpenAI-compatible providers like OpenRouter) and facing issues where the model “hallucinates” tool outputs instead of running them in multi-turn chats:

Check your AI Agent Node version.

  • Version 3 (Latest): BROKEN for this use case. It causes the conversation history formatting issues.
  • Version 2: WORKS PERFECTLY.

The Fix:
Simply switch your AI Agent node back to Version 2.
Combined with the OpenAI Chat Model node (Base URL: https://api.cerebras.ai/v1, “Use Responses API”: OFF), everything works 100% natively. No custom code needed.