From 709fe2b6465896cd9377f324f083707080155262 Mon Sep 17 00:00:00 2001 From: Yijia-Xiao Date: Sun, 21 Jun 2026 22:09:43 +0000 Subject: [PATCH] fix(graph): dedupe the trailing message in the debug stream Nodes after the trader do not append to messages, so the debug stream reprinted the same trailing message once per node. Print it only when it changes; the returned state is unchanged. --- tradingagents/graph/trading_graph.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index f72ede83d..253dd82be 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -381,11 +381,17 @@ class TradingAgentsGraph: if self.debug: trace = [] + last_printed = None for chunk in self.graph.stream(init_agent_state, **args): - if len(chunk["messages"]) == 0: - pass - else: - chunk["messages"][-1].pretty_print() + if chunk["messages"]: + msg = chunk["messages"][-1] + # Nodes after the trader don't append to messages, so the + # same trailing message repeats across chunks. Print it only + # when it changes (#1027); the trace/state merge is unchanged. + signature = (type(msg).__name__, getattr(msg, "content", None)) + if signature != last_printed: + msg.pretty_print() + last_printed = signature trace.append(chunk) # Streamed chunks are per-node deltas. Merge them so the returned # state matches what graph.invoke() yields in the non-debug path.