@langchain/mistralai: streamed GLM tool call split into two calls ("null" id), and parallel_tool_calls dropped
Checked other resources
- This is a bug, not a usage question.
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
import { ChatMistralAI } from "@langchain/mistralai";
import { HumanMessage } from "@langchain/core/messages";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const getWeather = tool(async () => "sunny", {
name: "get_weather",
description: "Get the weather for a city",
schema: z.object({ city: z.string() }),
});
const model = new ChatMistralAI({ model: "zai-glm-5-3", streaming: true })
.bindTools([getWeather], { tool_choice: "any" });
for (let i = 0; i < 3; i++) {
const res = await model.invoke([new HumanMessage("What's the weather in Paris?")]);
console.log(JSON.stringify(res.tool_calls.map((c) => ({ name: c.name, args: c.args }))));
}
// parallel_tool_calls is silently dropped
const m = new ChatMistralAI({ model: "zai-glm-5-3" });
console.log(m.invocationParams({ parallel_tool_calls: false }).parallelToolCalls); // undefinedError Message and Stack Trace (if applicable)
No error. One of three runs returned two tool calls for a single call:
[{"name":"get_weather","args":{"city":"Paris"}}]
[{"name":"get_weather","args":{"city":""}}]
[{"name":"get_weather","args":{}},{"name":"","args":{"city":"Paris"}}]Description
When streaming, GLM models on Mistral (zai-glm-5-2, zai-glm-5-3) sometimes send a tool call in two chunks: the first has the name, the continuation has the arguments and no id. The Mistral JS SDK fills the missing id with the string "null" (id: z.string().default("null") in toolcall.ts), and the adapter uses the chunk's array position instead of the API's index. LangChain then builds two tool calls: one with the name and empty args, one with no name. In an agent this becomes a tool call with no arguments, a tool error, and a retry loop.
Separately, parallel_tool_calls is not forwarded to the Mistral client, so parallel_tool_calls: false has no effect.
Fixed by #11373 (also covered by the narrower #11505).
Related: #11731 (other GLM bug: thinking chunks can't be sent back).
System Info
@langchain/mistralai1.2.0,@mistralai/mistralai2.7.0- Node 24, macOS
Source: langchain-ai/langchainjs