refactor: gather the memory log, settlement and reflection in tradingagents/memory

- memory/log.py holds TradingMemoryLog, still imported from tradingagents.memory
- graph/settlement.py and graph/reflection.py move to memory/; Reflector leaves tradingagents.graph's exports
This commit is contained in:
Yijia-Xiao
2026-09-24 19:38:41 +00:00
parent b690dc7988
commit c50420fc5c
9 changed files with 17 additions and 11 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ def test_settling_reads_the_graphs_own_config(monkeypatch):
graph = _graph(config) graph = _graph(config)
graph.memory_log = graph.reflector = None # the settlement below is a stand-in graph.memory_log = graph.reflector = None # the settlement below is a stand-in
seen = [] seen = []
from tradingagents.graph import settlement from tradingagents.memory import settlement
monkeypatch.setattr(settlement, "settle_pending", monkeypatch.setattr(settlement, "settle_pending",
lambda *a: seen.append(get_vendor("core_stock_apis", "get_stock_data"))) lambda *a: seen.append(get_vendor("core_stock_apis", "get_stock_data")))
+3 -4
View File
@@ -7,11 +7,10 @@ import pytest
from tradingagents.agents.managers.portfolio_manager import create_portfolio_manager from tradingagents.agents.managers.portfolio_manager import create_portfolio_manager
from tradingagents.agents.schemas import PortfolioDecision, PortfolioRating from tradingagents.agents.schemas import PortfolioDecision, PortfolioRating
from tradingagents.graph import settlement
from tradingagents.graph.propagation import Propagator from tradingagents.graph.propagation import Propagator
from tradingagents.graph.reflection import Reflector
from tradingagents.graph.trading_graph import TradingAgentsGraph from 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 _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(): def test_the_reflection_states_the_window_it_judges():
"""Judging a months-long thesis on a week's alpha, without saying so, turns """Judging a months-long thesis on a week's alpha, without saying so, turns
a scope mismatch into a lesson that the call was wrong.""" a scope mismatch into a lesson that the call was wrong."""
from tradingagents.graph.reflection import Reflector from tradingagents.memory.reflection import Reflector
prompt = Reflector(None)._system_prompt(holding_days=5) prompt = Reflector(None)._system_prompt(holding_days=5)
assert "5" in prompt and "trading day" in prompt assert "5" in prompt and "trading day" in prompt
+1 -1
View File
@@ -10,7 +10,7 @@ import pandas as pd
import tradingagents.agents.context as au import tradingagents.agents.context as au
import tradingagents.dataflows.vendors.yahoo.market as yahoo_market import tradingagents.dataflows.vendors.yahoo.market as yahoo_market
import tradingagents.dataflows.vendors.yahoo.news as ynews import tradingagents.dataflows.vendors.yahoo.news as ynews
from tradingagents.graph import settlement from tradingagents.memory import settlement
def test_identity_lookup_normalizes_symbol(monkeypatch): def test_identity_lookup_normalizes_symbol(monkeypatch):
-2
View File
@@ -1,6 +1,5 @@
from .conditional_logic import ConditionalLogic from .conditional_logic import ConditionalLogic
from .propagation import Propagator from .propagation import Propagator
from .reflection import Reflector
from .setup import GraphSetup from .setup import GraphSetup
from .trading_graph import TradingAgentsGraph from .trading_graph import TradingAgentsGraph
@@ -9,5 +8,4 @@ __all__ = [
"ConditionalLogic", "ConditionalLogic",
"GraphSetup", "GraphSetup",
"Propagator", "Propagator",
"Reflector",
] ]
+2 -3
View File
@@ -13,14 +13,13 @@ from tradingagents.dataflows.date_window import get_current_date
from tradingagents.dataflows.symbols import safe_ticker_component from tradingagents.dataflows.symbols import safe_ticker_component
from tradingagents.default_config import DEFAULT_CONFIG from tradingagents.default_config import DEFAULT_CONFIG
from tradingagents.llm_clients import build_llm_kwargs, create_llm_client from 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 Reflector
from tradingagents.reporting import write_report_tree from tradingagents.reporting import write_report_tree
from . import settlement
from .checkpointer import checkpoint_step, clear_checkpoint, get_checkpointer, thread_id from .checkpointer import checkpoint_step, clear_checkpoint, get_checkpointer, thread_id
from .conditional_logic import ConditionalLogic from .conditional_logic import ConditionalLogic
from .propagation import Propagator from .propagation import Propagator
from .reflection import Reflector
from .setup import GraphSetup from .setup import GraphSetup
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
+10
View File
@@ -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"]