When streaming using stream mode of messages I get token-by-token messages and full message at the end #977

Closed
opened 2026-02-20 17:42:35 -05:00 by yindo · 2 comments
Owner

Originally created by @yaserabdelaziz on GitHub (Sep 16, 2025).

Originally assigned to: @casparb on GitHub.

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 clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

for chunk_item in self.graph.stream(
    initial_state, config, stream_mode="messages"
):

Error Message and Stack Trace (if applicable)

Stream chunk: content=[{'type': 'text', 'text': ' HVAC Technical Support Resources', 'index': 0}] additional_kwargs={} response_metadata={} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2'
Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192}
Stream chunk: content=[{'type': 'text', 'text': '', 'index': 0}] additional_kwargs={} response_metadata={} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2'
Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192}
Stream chunk: content=[{'index': 0}] additional_kwargs={} response_metadata={} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2'
Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192}
Stream chunk: content=[] additional_kwargs={} response_metadata={'stopReason': 'end_turn'} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2'
Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192}
Stream chunk: content=[] additional_kwargs={} response_metadata={'metrics': {'latencyMs': 1047}, 'model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ResponseMetadata': {'RequestId': '4de582bd-9e16-4a7b-9cca-e61d59a98b10', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Tue, 16 Sep 2025 12:45:19 GMT', 'content-type': 'application/vnd.amazon.eventstream', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-amzn-requestid': '4de582bd-9e16-4a7b-9cca-e61d59a98b10'}, 'RetryAttempts': 0}} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2' usage_metadata={'input_tokens': 1001, 'output_tokens': 46, 'total_tokens': 1047, 'input_token_details': {'cache_creation': 0, 'cache_read': 0}}
Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192}
Stream chunk: content=[{'type': 'text', 'text': "Hello Gandalf! Welcome to Carrier HVAC technical support. I'm here to help with any questions or issues you have regarding your Carrier equipment. What can I assist you with today?\n\n# References\n1. Carrier HVAC Technical Support Resources", 'index': 0}] additional_kwargs={} response_metadata={} id='4699525b-4551-413c-991f-8a82fe7fc95c'
Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94'}

Description

When streaming using stream mode of messages I get token-by-token messages and full message at the end. In the past versions I was only having token-by-token messages. The full message at the end adds redundancy.

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025
Python Version: 3.12.11 (main, Sep 2 2025, 14:20:58) [Clang 20.1.4 ]

Package Information

langchain_core: 0.3.75
langchain: 0.3.27
langchain_community: 0.3.21
langsmith: 0.3.45
langchain_aws: 0.2.31
langchain_mcp_adapters: 0.1.9
langchain_mongodb: 0.7.0
langchain_openai: 0.3.32
langchain_text_splitters: 0.3.11
langgraph_sdk: 0.2.6

Optional packages not installed

langserve

Other Dependencies

aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
beautifulsoup4: Installed. No version info available.
bedrock-agentcore: Installed. No version info available.
boto3: 1.39.11
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
httpx: 0.27.2
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
httpx>=0.25.2: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<0.4,>=0.3.36: Installed. No version info available.
langchain-core<1.0.0,>=0.3.51: Installed. No version info available.
langchain-core<1.0.0,>=0.3.72: Installed. No version info available.
langchain-core<1.0.0,>=0.3.74: Installed. No version info available.
langchain-core<2.0.0,>=0.3.75: Installed. No version info available.
langchain-core>=0.3: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available.
langchain-text-splitters>=0.3: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langchain<1.0.0,>=0.3.23: Installed. No version info available.
langchain>=0.3: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
langsmith>=0.1.17: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
lark<2.0.0,>=1.1.9: Installed. No version info available.
mcp>=1.9.2: Installed. No version info available.
numpy: 1.26.4
numpy<3,>=1.26.2: Installed. No version info available.
numpy>=1.26: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.99.9: Installed. No version info available.
opentelemetry-api: 1.36.0
opentelemetry-exporter-otlp-proto-http: 1.36.0
opentelemetry-sdk: 1.36.0
orjson: 3.11.3
orjson>=3.10.1: Installed. No version info available.
packaging: 24.2
packaging>=23.2: Installed. No version info available.
playwright: Installed. No version info available.
pydantic: 2.11.7
pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pymongo>=4.6.1: Installed. No version info available.
pytest: 8.3.3
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.5
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
rich: 13.9.4
SQLAlchemy<3,>=1.4: Installed. No version info available.
tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.14.0: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0

Originally created by @yaserabdelaziz on GitHub (Sep 16, 2025). Originally assigned to: @casparb on GitHub. ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python for chunk_item in self.graph.stream( initial_state, config, stream_mode="messages" ): ``` ### Error Message and Stack Trace (if applicable) ```shell Stream chunk: content=[{'type': 'text', 'text': ' HVAC Technical Support Resources', 'index': 0}] additional_kwargs={} response_metadata={} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2' Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192} Stream chunk: content=[{'type': 'text', 'text': '', 'index': 0}] additional_kwargs={} response_metadata={} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2' Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192} Stream chunk: content=[{'index': 0}] additional_kwargs={} response_metadata={} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2' Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192} Stream chunk: content=[] additional_kwargs={} response_metadata={'stopReason': 'end_turn'} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2' Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192} Stream chunk: content=[] additional_kwargs={} response_metadata={'metrics': {'latencyMs': 1047}, 'model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ResponseMetadata': {'RequestId': '4de582bd-9e16-4a7b-9cca-e61d59a98b10', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Tue, 16 Sep 2025 12:45:19 GMT', 'content-type': 'application/vnd.amazon.eventstream', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-amzn-requestid': '4de582bd-9e16-4a7b-9cca-e61d59a98b10'}, 'RetryAttempts': 0}} id='run--86d8f139-51d7-4b92-858b-dbc10a7f8fc2' usage_metadata={'input_tokens': 1001, 'output_tokens': 46, 'total_tokens': 1047, 'input_token_details': {'cache_creation': 0, 'cache_read': 0}} Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94', 'ls_provider': 'amazon_bedrock', 'ls_model_name': 'us.meta.llama4-maverick-17b-instruct-v1:0', 'ls_model_type': 'chat', 'ls_max_tokens': 8192} Stream chunk: content=[{'type': 'text', 'text': "Hello Gandalf! Welcome to Carrier HVAC technical support. I'm here to help with any questions or issues you have regarding your Carrier equipment. What can I assist you with today?\n\n# References\n1. Carrier HVAC Technical Support Resources", 'index': 0}] additional_kwargs={} response_metadata={} id='4699525b-4551-413c-991f-8a82fe7fc95c' Stream metadata: {'thread_id': 'f92c93c9-9830-4473-a938-594d50409ba0', 'recursion_limit': 4, 'langgraph_step': 2, 'langgraph_node': 'final_answer', 'langgraph_triggers': ('branch:to:final_answer',), 'langgraph_path': ('__pregel_pull', 'final_answer'), 'langgraph_checkpoint_ns': 'final_answer:9ff545d7-9d6e-e89a-45df-05399c132c94'} ``` ### Description When streaming using stream mode of messages I get token-by-token messages and full message at the end. In the past versions I was only having token-by-token messages. The full message at the end adds redundancy. ### System Info System Information ------------------ > OS: Linux > OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 > Python Version: 3.12.11 (main, Sep 2 2025, 14:20:58) [Clang 20.1.4 ] Package Information ------------------- > langchain_core: 0.3.75 > langchain: 0.3.27 > langchain_community: 0.3.21 > langsmith: 0.3.45 > langchain_aws: 0.2.31 > langchain_mcp_adapters: 0.1.9 > langchain_mongodb: 0.7.0 > langchain_openai: 0.3.32 > langchain_text_splitters: 0.3.11 > langgraph_sdk: 0.2.6 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > beautifulsoup4: Installed. No version info available. > bedrock-agentcore: Installed. No version info available. > boto3: 1.39.11 > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > httpx: 0.27.2 > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > httpx>=0.25.2: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-azure-ai;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<0.4,>=0.3.36: Installed. No version info available. > langchain-core<1.0.0,>=0.3.51: Installed. No version info available. > langchain-core<1.0.0,>=0.3.72: Installed. No version info available. > langchain-core<1.0.0,>=0.3.74: Installed. No version info available. > langchain-core<2.0.0,>=0.3.75: Installed. No version info available. > langchain-core>=0.3: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-perplexity;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available. > langchain-text-splitters>=0.3: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain-xai;: Installed. No version info available. > langchain<1.0.0,>=0.3.23: Installed. No version info available. > langchain>=0.3: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith<0.4,>=0.1.125: Installed. No version info available. > langsmith>=0.1.17: Installed. No version info available. > langsmith>=0.3.45: Installed. No version info available. > lark<2.0.0,>=1.1.9: Installed. No version info available. > mcp>=1.9.2: Installed. No version info available. > numpy: 1.26.4 > numpy<3,>=1.26.2: Installed. No version info available. > numpy>=1.26: Installed. No version info available. > openai-agents: Installed. No version info available. > openai<2.0.0,>=1.99.9: Installed. No version info available. > opentelemetry-api: 1.36.0 > opentelemetry-exporter-otlp-proto-http: 1.36.0 > opentelemetry-sdk: 1.36.0 > orjson: 3.11.3 > orjson>=3.10.1: Installed. No version info available. > packaging: 24.2 > packaging>=23.2: Installed. No version info available. > playwright: Installed. No version info available. > pydantic: 2.11.7 > pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pymongo>=4.6.1: Installed. No version info available. > pytest: 8.3.3 > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.5 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > rich: 13.9.4 > SQLAlchemy<3,>=1.4: Installed. No version info available. > tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > typing-extensions>=4.14.0: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > zstandard: 0.23.0
yindo added the question label 2026-02-20 17:42:35 -05:00
yindo closed this issue 2026-02-20 17:42:35 -05:00
Author
Owner

@casparb commented on GitHub (Sep 17, 2025):

Hi @yaserabdelaziz, not sure what you mean. I can setup a simple graph:

from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
from langchain_core.messages import AnyMessage, HumanMessage
from langchain_openai import ChatOpenAI

class State(TypedDict):
    messages: list[AnyMessage]

llm = ChatOpenAI(model="gpt-4o")

def final_answer(state: State):
    resp = llm.invoke(state["messages"])
    return {"messages": [resp]}

builder = StateGraph(State)
builder.add_node("final_answer", final_answer)
builder.add_edge(START, "final_answer")
builder.add_edge("final_answer", END)
graph = builder.compile()

initial = {"messages": [HumanMessage(content="Reply with a short greeting, streaming tokens.")]}

for message, meta in graph.stream(initial, stream_mode="messages"):
    print("Stream chunk:", message)

Only the chunks are streamed, not a final message:

Stream chunk: content='' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303'
Stream chunk: content='Hello' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303'
Stream chunk: content=' there' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303'
Stream chunk: content='!' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303'
Stream chunk: content='' additional_kwargs={} response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_f33640a400', 'service_tier': 'default'} id='run--fa51ea5e-c308-4230-8925-f09085dd0303'

Our docs on streaming LLM tokens might help clear things up.

Closing as I can't help much without knowing what your graph looks like. Provide a MRE and I'd be happy to reopen.

@casparb commented on GitHub (Sep 17, 2025): Hi @yaserabdelaziz, not sure what you mean. I can setup a simple graph: ```python from typing_extensions import TypedDict from langgraph.graph import StateGraph, START, END from langchain_core.messages import AnyMessage, HumanMessage from langchain_openai import ChatOpenAI class State(TypedDict): messages: list[AnyMessage] llm = ChatOpenAI(model="gpt-4o") def final_answer(state: State): resp = llm.invoke(state["messages"]) return {"messages": [resp]} builder = StateGraph(State) builder.add_node("final_answer", final_answer) builder.add_edge(START, "final_answer") builder.add_edge("final_answer", END) graph = builder.compile() initial = {"messages": [HumanMessage(content="Reply with a short greeting, streaming tokens.")]} for message, meta in graph.stream(initial, stream_mode="messages"): print("Stream chunk:", message) ``` Only the chunks are streamed, not a final message: ``` Stream chunk: content='' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303' Stream chunk: content='Hello' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303' Stream chunk: content=' there' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303' Stream chunk: content='!' additional_kwargs={} response_metadata={} id='run--fa51ea5e-c308-4230-8925-f09085dd0303' Stream chunk: content='' additional_kwargs={} response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_f33640a400', 'service_tier': 'default'} id='run--fa51ea5e-c308-4230-8925-f09085dd0303' ``` Our docs on [streaming LLM tokens](https://docs.langchain.com/oss/python/langgraph/streaming#llm-tokens) might help clear things up. Closing as I can't help much without knowing what your graph looks like. Provide a MRE and I'd be happy to reopen.
Author
Owner

@kvpratama commented on GitHub (Dec 26, 2025):

I ran into the same issue and tracked down the cause:

response = llm.invoke(messages)
# ❌ This recreates a new AIMessage, which causes the final complete message to be emitted again
return {
    "messages": [AIMessage(content=response.content, name="customer_service")]
}

The solution is to return the original response object from the LLM instead:

response = llm.invoke(messages)
# ✅ This only streams chunks, no duplicate complete message
return {
    "messages": [response]
}

From what I can tell, LangGraph seems to track messages by their ID. My guess is that by recreating a new AIMessage, it ends up with a different ID than the streamed chunks, so LangGraph treats it as new content and emits it again.

@kvpratama commented on GitHub (Dec 26, 2025): I ran into the same issue and tracked down the cause: ```python response = llm.invoke(messages) # ❌ This recreates a new AIMessage, which causes the final complete message to be emitted again return { "messages": [AIMessage(content=response.content, name="customer_service")] } ``` The solution is to return the **original response object** from the LLM instead: ```python response = llm.invoke(messages) # ✅ This only streams chunks, no duplicate complete message return { "messages": [response] } ``` From what I can tell, LangGraph seems to track messages by their ID. My guess is that by recreating a new AIMessage, it ends up with a different ID than the streamed chunks, so LangGraph treats it as new content and emits it again.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#977