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 withstream_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.createdchunk has theresp_…id. Every later chunk hasid=None, soBaseChatModel.stream/astreamfills inlc_run--<run_id>. When the chunks are merged,add_ai_message_chunksprefers the provider id, so the final message isresp_…:
| 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