Python
refactor: gather the memory log, settlement and reflection in tradingagents/memory
Yijia-Xiaoc50420fc5ce5
diff --git a/tests/test_dataflows_config.py b/tests/test_dataflows_config.pyindex fd1ef37e5..dd0393c27 100644--- a/tests/test_dataflows_config.py+++ b/tests/test_dataflows_config.py@@ -148,7 +148,7 @@ def test_settling_reads_the_graphs_own_config(monkeypatch):graph = _graph(config)graph.memory_log = graph.reflector = None # the settlement below is a stand-inseen = []- from tradingagents.graph import settlement+ from tradingagents.memory import settlementmonkeypatch.setattr(settlement, "settle_pending",lambda *a: seen.append(get_vendor("core_stock_apis", "get_stock_data")))diff --git a/tests/test_memory_log.py b/tests/test_memory_log.pyindex 5ceb01ac8..7652aafde 100644--- a/tests/test_memory_log.py+++ b/tests/test_memory_log.py@@ -7,11 +7,10 @@ import pytestfrom tradingagents.agents.managers.portfolio_manager import create_portfolio_managerfrom tradingagents.agents.schemas import PortfolioDecision, PortfolioRating-from tradingagents.graph import settlementfrom tradingagents.graph.propagation import Propagator-from tradingagents.graph.reflection import Reflectorfrom tradingagents.graph.trading_graph import TradingAgentsGraph-from tradingagents.memory import TradingMemoryLog+from tradingagents.memory import TradingMemoryLog, settlement+from tradingagents.memory.reflection import Reflector_SEP = TradingMemoryLog._SEPARATOR@@ -1004,7 +1003,7 @@ def test_the_holding_window_is_configurable(tmp_path, monkeypatch):def test_the_reflection_states_the_window_it_judges():"""Judging a months-long thesis on a week's alpha, without saying so, turnsa scope mismatch into a lesson that the call was wrong."""- from tradingagents.graph.reflection import Reflector+ from tradingagents.memory.reflection import Reflectorprompt = Reflector(None)._system_prompt(holding_days=5)assert "5" in prompt and "trading day" in promptdiff --git a/tests/test_symbol_normalization_paths.py b/tests/test_symbol_normalization_paths.pyindex f802ae53b..f3ed1b21d 100644--- a/tests/test_symbol_normalization_paths.py+++ b/tests/test_symbol_normalization_paths.py@@ -10,7 +10,7 @@ import pandas as pdimport tradingagents.agents.context as auimport tradingagents.dataflows.vendors.yahoo.market as yahoo_marketimport tradingagents.dataflows.vendors.yahoo.news as ynews-from tradingagents.graph import settlement+from tradingagents.memory import settlementdef test_identity_lookup_normalizes_symbol(monkeypatch):diff --git a/tradingagents/graph/__init__.py b/tradingagents/graph/__init__.pyindex 54f3037fc..e3715701b 100644--- a/tradingagents/graph/__init__.py+++ b/tradingagents/graph/__init__.py@@ -1,6 +1,5 @@from .conditional_logic import ConditionalLogicfrom .propagation import Propagator-from .reflection import Reflectorfrom .setup import GraphSetupfrom .trading_graph import TradingAgentsGraph@@ -9,5 +8,4 @@ __all__ = ["ConditionalLogic","GraphSetup","Propagator",- "Reflector",]diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.pyindex 9fe826977..1795907db 100644--- a/tradingagents/graph/trading_graph.py+++ b/tradingagents/graph/trading_graph.py@@ -13,14 +13,13 @@ from tradingagents.dataflows.date_window import get_current_datefrom tradingagents.dataflows.symbols import safe_ticker_componentfrom tradingagents.default_config import DEFAULT_CONFIGfrom tradingagents.llm_clients import build_llm_kwargs, create_llm_client-from tradingagents.memory import TradingMemoryLog+from tradingagents.memory import TradingMemoryLog, settlement+from tradingagents.memory.reflection import Reflectorfrom tradingagents.reporting import write_report_tree-from . import settlementfrom .checkpointer import checkpoint_step, clear_checkpoint, get_checkpointer, thread_idfrom .conditional_logic import ConditionalLogicfrom .propagation import Propagator-from .reflection import Reflectorfrom .setup import GraphSetuplogger = logging.getLogger(__name__)diff --git a/tradingagents/memory/__init__.py b/tradingagents/memory/__init__.pynew file mode 100644index 000000000..04c764230--- /dev/null+++ b/tradingagents/memory/__init__.py@@ -0,0 +1,10 @@+"""The memory log: each decision recorded as made, settled against the market, and reflected on.++``log`` keeps the entries, ``settlement`` measures a decision's return once its+holding window has traded, and ``reflection`` turns that outcome into a lesson+the next run of the same ticker reads.+"""++from tradingagents.memory.log import TradingMemoryLog++__all__ = ["TradingMemoryLog"]diff --git a/tradingagents/memory.py b/tradingagents/memory/log.pysimilarity index 100%rename from tradingagents/memory.pyrename to tradingagents/memory/log.pydiff --git a/tradingagents/graph/reflection.py b/tradingagents/memory/reflection.pysimilarity index 100%rename from tradingagents/graph/reflection.pyrename to tradingagents/memory/reflection.pydiff --git a/tradingagents/graph/settlement.py b/tradingagents/memory/settlement.pysimilarity index 100%rename from tradingagents/graph/settlement.pyrename to tradingagents/memory/settlement.py