astream does not return subgraph output and llm tokens like stream #547

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

Originally created by @XiaoLiuAI on GitHub (Apr 1, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • 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

from typing import TypedDict
from langgraph.constants import END, START
from langgraph.graph import StateGraph, add_messages
from langgraph.types import Send


# Define subgraph
class SubgraphState(TypedDict):
    # note that none of these keys are shared with the parent graph state
    bar: str
    baz: str


async def subgraph_node_1(state: SubgraphState):
    return {"baz": "baz"}


async def subgraph_node_2(state: SubgraphState):
    return {"bar": state["bar"] + state["baz"]}


subgraph_builder = StateGraph(SubgraphState)
subgraph_builder.add_node(subgraph_node_1)
subgraph_builder.add_node(subgraph_node_2)
subgraph_builder.add_edge(START, "subgraph_node_1")
subgraph_builder.add_edge("subgraph_node_1", "subgraph_node_2")
subgraph = subgraph_builder.compile()


# Define parent graph
class ParentState(TypedDict):
    foo: str


async def node_1(state: ParentState):
    return {"foo": "hi! " + state["foo"]}


async def node_2(state: ParentState):
    # transform the state to the subgraph state
    response = await subgraph.ainvoke({"bar": state["foo"]})
    # transform response back to the parent state
    return {"foo": response["bar"]}


builder = StateGraph(ParentState)
builder.add_node("node_1", node_1)
# note that instead of using the compiled subgraph we are using `node_2` function that is calling the subgraph
builder.add_node("node_2", node_2)
builder.add_edge(START, "node_1")
builder.add_edge("node_1", "node_2")
graph = builder.compile()

async for chunk in graph.astream({"foo": "foo"}, subgraphs=True):
    print(chunk)

Error Message and Stack Trace (if applicable)


Description

I'm trying to stream the subgraph output in with async api. but the output does not like sync api.
I tried the example code in tutorial, with graph.stream(input, subgraphs=True, stream_mode=['updates']), I got the subgraph out, with graph.astream(input, subgraph=True, stream_mode=['updates']) I got only the output of parent graph.

This also exist for stream_mode=['messages'] to stream the llm token.

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:22:00 PST 2025; root:xnu-11215.81.4~3/RELEASE_X86_64
Python Version: 3.10.16 (main, Mar 18 2025, 09:30:41) [Clang 16.0.0 (clang-1600.0.26.6)]

Package Information

langchain_core: 0.3.49
langchain: 0.3.21
langchain_community: 0.3.20
langsmith: 0.3.19
langchain_huggingface: 0.1.2
langchain_milvus: 0.1.8
langchain_openai: 0.3.11
langchain_text_splitters: 0.3.7
langgraph_sdk: 0.1.60

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.
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
huggingface-hub: 0.29.3
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<1.0.0,>=0.3.45: Installed. No version info available.
langchain-core<1.0.0,>=0.3.49: 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-text-splitters<1.0.0,>=0.3.7: 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.21: 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.4,>=0.1.17: Installed. No version info available.
numpy<3,>=1.26.2: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.68.2: Installed. No version info available.
opentelemetry-api: 1.31.0
opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
opentelemetry-sdk: 1.31.0
orjson: 3.10.15
packaging: 24.2
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.10.3
pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
pymilvus: 2.5.3
pytest: 8.3.5
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.3
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
rich: 13.9.4
sentence-transformers: 3.3.1
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.
tokenizers: 0.21.1
transformers: 4.49.0
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0

Originally created by @XiaoLiuAI on GitHub (Apr 1, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [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 from typing import TypedDict from langgraph.constants import END, START from langgraph.graph import StateGraph, add_messages from langgraph.types import Send # Define subgraph class SubgraphState(TypedDict): # note that none of these keys are shared with the parent graph state bar: str baz: str async def subgraph_node_1(state: SubgraphState): return {"baz": "baz"} async def subgraph_node_2(state: SubgraphState): return {"bar": state["bar"] + state["baz"]} subgraph_builder = StateGraph(SubgraphState) subgraph_builder.add_node(subgraph_node_1) subgraph_builder.add_node(subgraph_node_2) subgraph_builder.add_edge(START, "subgraph_node_1") subgraph_builder.add_edge("subgraph_node_1", "subgraph_node_2") subgraph = subgraph_builder.compile() # Define parent graph class ParentState(TypedDict): foo: str async def node_1(state: ParentState): return {"foo": "hi! " + state["foo"]} async def node_2(state: ParentState): # transform the state to the subgraph state response = await subgraph.ainvoke({"bar": state["foo"]}) # transform response back to the parent state return {"foo": response["bar"]} builder = StateGraph(ParentState) builder.add_node("node_1", node_1) # note that instead of using the compiled subgraph we are using `node_2` function that is calling the subgraph builder.add_node("node_2", node_2) builder.add_edge(START, "node_1") builder.add_edge("node_1", "node_2") graph = builder.compile() async for chunk in graph.astream({"foo": "foo"}, subgraphs=True): print(chunk) ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description I'm trying to stream the subgraph output in with async api. but the output does not like sync api. I tried the example code in tutorial, with graph.stream(input, subgraphs=True, stream_mode=['updates']), I got the subgraph out, with graph.astream(input, subgraph=True, stream_mode=['updates']) I got only the output of parent graph. This also exist for stream_mode=['messages'] to stream the llm token. ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:22:00 PST 2025; root:xnu-11215.81.4~3/RELEASE_X86_64 > Python Version: 3.10.16 (main, Mar 18 2025, 09:30:41) [Clang 16.0.0 (clang-1600.0.26.6)] Package Information ------------------- > langchain_core: 0.3.49 > langchain: 0.3.21 > langchain_community: 0.3.20 > langsmith: 0.3.19 > langchain_huggingface: 0.1.2 > langchain_milvus: 0.1.8 > langchain_openai: 0.3.11 > langchain_text_splitters: 0.3.7 > langgraph_sdk: 0.1.60 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. > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > httpx: 0.28.1 > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > huggingface-hub: 0.29.3 > 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<1.0.0,>=0.3.45: Installed. No version info available. > langchain-core<1.0.0,>=0.3.49: 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-text-splitters<1.0.0,>=0.3.7: 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.21: 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.4,>=0.1.17: Installed. No version info available. > numpy<3,>=1.26.2: Installed. No version info available. > openai-agents: Installed. No version info available. > openai<2.0.0,>=1.68.2: Installed. No version info available. > opentelemetry-api: 1.31.0 > opentelemetry-exporter-otlp-proto-http: Installed. No version info available. > opentelemetry-sdk: 1.31.0 > orjson: 3.10.15 > packaging: 24.2 > packaging<25,>=23.2: Installed. No version info available. > pydantic: 2.10.3 > pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. > pydantic<3.0.0,>=2.5.2;: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic<3.0.0,>=2.7.4;: Installed. No version info available. > pymilvus: 2.5.3 > pytest: 8.3.5 > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.3 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > rich: 13.9.4 > sentence-transformers: 3.3.1 > 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. > tokenizers: 0.21.1 > transformers: 4.49.0 > typing-extensions>=4.7: Installed. No version info available. > zstandard: 0.23.0
yindo closed this issue 2026-02-20 17:40:40 -05:00
Author
Owner

@XiaoLiuAI commented on GitHub (Apr 1, 2025):

I tried to modify subgraph.invoke into subgraph.ainvoke and it acted the same.

@XiaoLiuAI commented on GitHub (Apr 1, 2025): I tried to modify `subgraph.invoke` into `subgraph.ainvoke` and it acted the same.
Author
Owner

@XiaoLiuAI commented on GitHub (Apr 2, 2025):

Got a solution, update python from 3.10 to 3.12 and it works.

@XiaoLiuAI commented on GitHub (Apr 2, 2025): Got a solution, update python from 3.10 to 3.12 and it works.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#547