Python
Fix: Prevent infinite loops, enable reflection, and improve logging
mirza-samad-ahmed-baigf704828f89d1
diff --git a/main.py b/main.pyindex 6c8ae3d9e..077dfb8eb 100644--- a/main.py+++ b/main.py@@ -18,4 +18,4 @@ _, decision = ta.propagate("NVDA", "2024-05-10")print(decision)# Memorize mistakes and reflect-# ta.reflect_and_remember(1000) # parameter is the position returns+ta.reflect_and_remember(1000) # parameter is the position returnsdiff --git a/tradingagents/agents/trader/trader.py b/tradingagents/agents/trader/trader.pyindex 282a84117..1b05c35d5 100644--- a/tradingagents/agents/trader/trader.py+++ b/tradingagents/agents/trader/trader.py@@ -16,8 +16,11 @@ def create_trader(llm, memory):past_memories = memory.get_memories(curr_situation, n_matches=2)past_memory_str = ""- for i, rec in enumerate(past_memories, 1):- past_memory_str += rec["recommendation"] + "\n\n"+ if past_memories:+ for i, rec in enumerate(past_memories, 1):+ past_memory_str += rec["recommendation"] + "\n\n"+ else:+ past_memory_str = "No past memories found."context = {"role": "user",diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.pyindex eb06cf437..80a29e539 100644--- a/tradingagents/graph/trading_graph.py+++ b/tradingagents/graph/trading_graph.py@@ -226,7 +226,7 @@ class TradingAgentsGraph:directory.mkdir(parents=True, exist_ok=True)with open(- f"eval_results/{self.ticker}/TradingAgentsStrategy_logs/full_states_log.json",+ f"eval_results/{self.ticker}/TradingAgentsStrategy_logs/full_states_log_{trade_date}.json","w",) as f:json.dump(self.log_states_dict, f, indent=4)