diff --git a/tradingagents/graph/portfolio_analysis.py b/tradingagents/graph/portfolio_analysis.py index 2af2a2bf..6cf3f709 100644 --- a/tradingagents/graph/portfolio_analysis.py +++ b/tradingagents/graph/portfolio_analysis.py @@ -61,7 +61,11 @@ class PortfolioAnalyzer: individual_results, trade_date ) - self._log_portfolio(trade_date, tickers, individual_results, portfolio_summary) + try: + self._log_portfolio(trade_date, tickers, individual_results, portfolio_summary) + except OSError as e: + if debug: + print(f"Warning: failed to save portfolio log: {e}") return { "individual_results": individual_results, diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index 7db0624e..6362dc49 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -283,6 +283,7 @@ class TradingAgentsGraph: """ original_ticker = self.ticker original_curr_state = self.curr_state + original_log_states = self.log_states_dict.copy() try: return self.portfolio_analyzer.analyze( tickers, trade_date, self.propagate, debug=self.debug @@ -290,6 +291,7 @@ class TradingAgentsGraph: finally: self.ticker = original_ticker self.curr_state = original_curr_state + self.log_states_dict = original_log_states def reflect_and_remember(self, returns_losses): """Reflect on decisions and update memory based on returns."""