#40871·长链

ChatOpenAI (Responses API): 流式数据块从 resp_… 切换为 lc_run--… ID, 流式 ID 不匹配最终消息 ID

作者: mike-iqmo创建于 2026年9月28日更新于 2026年9月28日
标签bugopenaiexternal
  • I'm streaming ChatOpenAI(use_responses_api=True) inside a LangGraph agent with stream_mode="messages", and the frontend matches streamed chunks to the final state by message id.
  • I expect every chunk of one response to carry the same id, and that id to match the final AIMessage.
  • Instead, only the response.created chunk has the resp_… id. Every later chunk has id=None, so BaseChatModel.stream / astream fills in lc_run--<run_id>. When the chunks are merged, add_ai_message_chunks prefers the provider id, so the final message is resp_…:
Source id
First chunk (response.created, no content) resp_…
All content chunks lc_run--…
Final merged AIMessage / graph state resp_…

The streamed text and

内容来源: langchain-ai/langchain