From c405867bde1627bb573ea069f0531569a631e594 Mon Sep 17 00:00:00 2001 From: Yijia-Xiao Date: Sun, 10 May 2026 19:20:23 +0000 Subject: [PATCH] fix: merge streamed chunks into final_state so reports save correctly graph.stream() yields per-node deltas, not the full state. Taking trace[-1] only captured the last node's contribution, so reports saved to disk were missing every section except the final decision. Merge all chunks in both the CLI path and trading_graph._run_graph's debug branch. #719 #736 --- cli/main.py | 7 +++++-- tradingagents/graph/trading_graph.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/main.py b/cli/main.py index 05376ade2..42794821d 100644 --- a/cli/main.py +++ b/cli/main.py @@ -1154,8 +1154,11 @@ def run_analysis(checkpoint: bool = False): trace.append(chunk) - # Get final state and decision - final_state = trace[-1] + # Streamed chunks are per-node deltas, not full state. Merge them + # so every report field populated across the run is present. + final_state = {} + for chunk in trace: + final_state.update(chunk) decision = graph.process_signal(final_state["final_trade_decision"]) # Update all agent statuses to completed diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index d7e8b5731..197913e21 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -322,7 +322,11 @@ class TradingAgentsGraph: else: chunk["messages"][-1].pretty_print() trace.append(chunk) - final_state = trace[-1] + # Streamed chunks are per-node deltas. Merge them so the returned + # state matches what graph.invoke() yields in the non-debug path. + final_state = {} + for chunk in trace: + final_state.update(chunk) else: final_state = self.graph.invoke(init_agent_state, **args)