#11762·langchainjs

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

typescript
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-start takes its id from the first chunk. Azure's first chunk has id: "", and BaseChatModel's run-<runId> fallback only applies when the id is null, so under streamEvents v3 every AIMessage gets id: "".
  • messagesStateReducer also only assigns ids to null/undefined. It merges all those messages as one, so each new AIMessage replaces the previous one.
  • As a result, a createAgent run that needs two tool rounds loses its first AIMessage. The state ends with [human, ai(round-2 tool calls), tool(round-1 results)], the router exits, and there's no structuredResponse.
  • 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