Python
fix: merge streamed chunks into final_state so reports save correctly
Yijia-Xiaoc405867bde16
diff --git a/cli/main.py b/cli/main.pyindex 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 completeddiff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.pyindex 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)