Python
fix(graph): dedupe the trailing message in the debug stream
Yijia-Xiao709fe2b64658
diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.pyindex 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 = Nonefor 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 = signaturetrace.append(chunk)# Streamed chunks are per-node deltas. Merge them so the returned# state matches what graph.invoke() yields in the non-debug path.