Azure's empty stream chunk id gives every AIMessage `id: ""`, breaking createAgent
Author: SiKreuzCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbug
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- 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 { convertOpenAICompletionsStream } from "@langchain/core/language_models/openai_completions_stream";
async function* azureStream() {
// Azure OpenAI's first chunk: content-filter results, no choices, empty id
yield { id: "", model: "", choices: [] };
yield { id: "chatcmpl-abc", model: "gpt-4o", choices: [{ index: 0, delta: { role: "assistant", content: "Hi" }, finish_reason: null }] };
yield { id: "chatcmpl-abc", model: "gpt-4o", choices: [{ index: 0, delta: {}, finish_reason: "stop" }] };
}
for await (const event of convertOpenAICompletionsStream(azureStream())) {
if (event.event === "message-start") console.log(JSON.stringify(event.id)); // ""
}Error Message and Stack Trace (if applicable)
No error from LangChain itself. Downstream, createAgent with responseFormat exits with structuredResponse: undefined:
TypeError: undefined is not an object (evaluating 'result.structuredResponse.questions')
Description
message-starttakes its id from the first chunk. Azure's first chunk hasid: "", andBaseChatModel'srun-<runId>fallback only applies when the id isnull, so understreamEventsv3 everyAIMessagegetsid: "".messagesStateReduceralso only assigns ids tonull/undefined. It merges all those messages as one, so each newAIMessagereplaces the previous one.- As a result, a
createAgentrun that needs two tool rounds loses its firstAIMessage. The state ends with[human, ai(round-2 tool calls), tool(round-1 results)], the router exits, and there's nostructuredResponse. - Expected: an empty chunk id is treated as missing and the run-id fallback applies
System Info
@langchain/core 1.2.13 langchain 1.5.14 @langchain/langgraph 1.4.18 @langchain/openai 1.6.0 (Azure OpenAI, Chat Completions, gpt-5.4) Bun 1.4.2 Linux (prod) / macOS (repro)
Source: langchain-ai/langchainjs