Two print in one step: When use for step in graph.stream #738

Closed
opened 2026-02-20 17:41:31 -05:00 by yindo · 1 comment
Owner

Originally created by @Xiaoshouzhen on GitHub (Jun 24, 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

builder = StateGraph(State)
builder.add_edge(START, "coordinator")
builder.add_node("coordinator", coordinator_node)
builder.add_node("planner", planner_node)
builder.add_node("supervisor", supervisor_node)
builder.add_node("data_gatherer", data_gatherer_node)
# builder.add_node("reporter", data_gatherer)
# builder.add_edge("reporter", )
g = builder.compile()
#
input = "哪天的生产质量较差?"
st = State(messages=[HumanMessage(content=input)],
           TEAM_MEMBERS=TEAM_MEMBERS,
           next="",
           full_plan="",
           deep_thinking_mode=False,
           search_before_planning=False,
           next_description="",
           query_data=[])

for step, met in g.stream(
        st,
        stream_mode="values",
        subgraphs=True
):

    met["messages"][-1].pretty_print()

Error Message and Stack Trace (if applicable)


Description

i use graph.stream(include a subgraph), i expect the out of stream is one time, but the process out is Two time, i receive follow out, the question is the same out will print again when next node update messages.

add: I use command method to update messages,like this:

def supervisor_node(state: State) -> Command[Literal["data_gatherer"]]:
    messages = apply_prompt_template("supervisor", state)
    response = get_llm(0.7).with_structured_output(Router).invoke(messages)
    goto = response["next"]
    task = response["task_description"]
    if goto == "FINISH":
        goto = "__end__"
    return Command(
        update={
            "next": goto,
            "next_description": task
        },
        goto=goto,

    )

System Info

================================== Ai Message ==================================
Name: planner
{
"thought": "用户询问哪一天的生产质量较差,需要分析生产数据以识别质量问题发生的日期。",
"title": "分析生产质量差异并定位问题日期",
"steps": [
{
"agent_name": "data_gatherer",
"title": "收集全量生产数据",
"description": "从数据库提取所有生产记录,包括生产日期、产品批次、质检结果、缺陷类型及数量等核心字段。确保覆盖近3年的完整数据集。",
"note": "需包含时间维度、质量指标和生产参数的原始数据"
},
{
"agent_name": "organizer",
"title": "结构化生产质量数据",
"description": "按日期粒度整理数据,计算每日合格率、缺陷密度、客户投诉率等关键质量指标,建立标准化时间序列数据库。",
"note": "需消除数据冗余并补充缺失值"
},
{
"agent_name": "analyzer",
"title": "识别异常质量波动",
"description": "运用统计过程控制(SPC)方法分析每日质量指标,结合趋势分析和假设检验定位显著偏离正常范围的日期。",
"note": "需考虑季节性因素和生产规模变化"
},
{
"agent_name": "reporter",
"title": "生成质量异常报告",
"description": "输出包含问题日期列表、关键缺陷类型、可能影响因素及改善建议的正式分析报告。",
"note": "需用可视化图表展示异常波动点"
}
]
}
================================== Ai Message ==================================
Name: planner
{
"thought": "用户询问哪一天的生产质量较差,需要分析生产数据以识别质量问题发生的日期。",
"title": "分析生产质量差异并定位问题日期",
"steps": [
{
"agent_name": "data_gatherer",
"title": "收集全量生产数据",
"description": "从数据库提取所有生产记录,包括生产日期、产品批次、质检结果、缺陷类型及数量等核心字段。确保覆盖近3年的完整数据集。",
"note": "需包含时间维度、质量指标和生产参数的原始数据"
},
{
"agent_name": "organizer",
"title": "结构化生产质量数据",
"description": "按日期粒度整理数据,计算每日合格率、缺陷密度、客户投诉率等关键质量指标,建立标准化时间序列数据库。",
"note": "需消除数据冗余并补充缺失值"
},
{
"agent_name": "analyzer",
"title": "识别异常质量波动",
"description": "运用统计过程控制(SPC)方法分析每日质量指标,结合趋势分析和假设检验定位显著偏离正常范围的日期。",
"note": "需考虑季节性因素和生产规模变化"
},
{
"agent_name": "reporter",
"title": "生成质量异常报告",
"description": "输出包含问题日期列表、关键缺陷类型、可能影响因素及改善建议的正式分析报告。",
"note": "需用可视化图表展示异常波动点"
}
]
}

Originally created by @Xiaoshouzhen on GitHub (Jun 24, 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 builder = StateGraph(State) builder.add_edge(START, "coordinator") builder.add_node("coordinator", coordinator_node) builder.add_node("planner", planner_node) builder.add_node("supervisor", supervisor_node) builder.add_node("data_gatherer", data_gatherer_node) # builder.add_node("reporter", data_gatherer) # builder.add_edge("reporter", ) g = builder.compile() # input = "哪天的生产质量较差?" st = State(messages=[HumanMessage(content=input)], TEAM_MEMBERS=TEAM_MEMBERS, next="", full_plan="", deep_thinking_mode=False, search_before_planning=False, next_description="", query_data=[]) for step, met in g.stream( st, stream_mode="values", subgraphs=True ): met["messages"][-1].pretty_print() ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description i use graph.stream(include a subgraph), i expect the out of stream is one time, but the process out is Two time, i receive follow out, the question is the same out will print again when next node update messages. add: I use command method to update messages,like this: ```python def supervisor_node(state: State) -> Command[Literal["data_gatherer"]]: messages = apply_prompt_template("supervisor", state) response = get_llm(0.7).with_structured_output(Router).invoke(messages) goto = response["next"] task = response["task_description"] if goto == "FINISH": goto = "__end__" return Command( update={ "next": goto, "next_description": task }, goto=goto, ) ``` ### System Info ================================== Ai Message ================================== Name: planner { "thought": "用户询问哪一天的生产质量较差,需要分析生产数据以识别质量问题发生的日期。", "title": "分析生产质量差异并定位问题日期", "steps": [ { "agent_name": "data_gatherer", "title": "收集全量生产数据", "description": "从数据库提取所有生产记录,包括生产日期、产品批次、质检结果、缺陷类型及数量等核心字段。确保覆盖近3年的完整数据集。", "note": "需包含时间维度、质量指标和生产参数的原始数据" }, { "agent_name": "organizer", "title": "结构化生产质量数据", "description": "按日期粒度整理数据,计算每日合格率、缺陷密度、客户投诉率等关键质量指标,建立标准化时间序列数据库。", "note": "需消除数据冗余并补充缺失值" }, { "agent_name": "analyzer", "title": "识别异常质量波动", "description": "运用统计过程控制(SPC)方法分析每日质量指标,结合趋势分析和假设检验定位显著偏离正常范围的日期。", "note": "需考虑季节性因素和生产规模变化" }, { "agent_name": "reporter", "title": "生成质量异常报告", "description": "输出包含问题日期列表、关键缺陷类型、可能影响因素及改善建议的正式分析报告。", "note": "需用可视化图表展示异常波动点" } ] } ================================== Ai Message ================================== Name: planner { "thought": "用户询问哪一天的生产质量较差,需要分析生产数据以识别质量问题发生的日期。", "title": "分析生产质量差异并定位问题日期", "steps": [ { "agent_name": "data_gatherer", "title": "收集全量生产数据", "description": "从数据库提取所有生产记录,包括生产日期、产品批次、质检结果、缺陷类型及数量等核心字段。确保覆盖近3年的完整数据集。", "note": "需包含时间维度、质量指标和生产参数的原始数据" }, { "agent_name": "organizer", "title": "结构化生产质量数据", "description": "按日期粒度整理数据,计算每日合格率、缺陷密度、客户投诉率等关键质量指标,建立标准化时间序列数据库。", "note": "需消除数据冗余并补充缺失值" }, { "agent_name": "analyzer", "title": "识别异常质量波动", "description": "运用统计过程控制(SPC)方法分析每日质量指标,结合趋势分析和假设检验定位显著偏离正常范围的日期。", "note": "需考虑季节性因素和生产规模变化" }, { "agent_name": "reporter", "title": "生成质量异常报告", "description": "输出包含问题日期列表、关键缺陷类型、可能影响因素及改善建议的正式分析报告。", "note": "需用可视化图表展示异常波动点" } ] }
yindo added the bugpending labels 2026-02-20 17:41:31 -05:00
yindo closed this issue 2026-02-20 17:41:31 -05:00
Author
Owner

@sydney-runkle commented on GitHub (Jun 27, 2025):

I believe you can use subgraphs=False to fix this. Please open a new issue with a MRE if you'd like further assistance.

@sydney-runkle commented on GitHub (Jun 27, 2025): I believe you can use `subgraphs=False` to fix this. Please open a new issue with a MRE if you'd like further assistance.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#738