mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-27 23:12:39 +03:00
feat(reports): record the analysis date and what produced a run (#752)
- TradingAgentsGraph.run_settings(): version, provider, models, analysts, debate rounds, language and vendors; no endpoints, keys or paths - complete_report.md opens with the analysis date and those settings; the saved state log carries them as run_settings
This commit is contained in:
@@ -61,7 +61,10 @@ def _bare_graph(tmp_path):
|
||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||
|
||||
graph = object.__new__(TradingAgentsGraph)
|
||||
graph.config = {"results_dir": str(tmp_path)}
|
||||
graph.config = {"results_dir": str(tmp_path), "llm_provider": "openai", "deep_think_llm": "d",
|
||||
"quick_think_llm": "q", "max_debate_rounds": 1, "max_risk_discuss_rounds": 1,
|
||||
"output_language": "English", "data_vendors": {}, "tool_vendors": {}}
|
||||
graph.selected_analysts = ("market",)
|
||||
return graph
|
||||
|
||||
|
||||
@@ -87,6 +90,7 @@ def test_the_state_log_names_each_field_as_the_state_does(tmp_path):
|
||||
assert logged["investment_plan"] == "计划"
|
||||
assert "trader_investment_decision" not in logged
|
||||
assert "judge_decision" not in json.dumps(logged)
|
||||
assert logged["run_settings"]["deep_think_llm"] == "d"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
+57
-3
@@ -21,6 +21,11 @@ def _state():
|
||||
}
|
||||
|
||||
|
||||
SETTINGS = {"version": "0.5.2", "llm_provider": "openai", "deep_think_llm": "gpt-6-sol",
|
||||
"quick_think_llm": "gpt-6-luna", "analysts": ["market", "news"], "max_debate_rounds": 1,
|
||||
"max_risk_discuss_rounds": 2, "data_vendors": {"core_stock_apis": "yfinance"}}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_write_report_tree_creates_files(tmp_path):
|
||||
out = write_report_tree(_state(), "AAPL", tmp_path)
|
||||
@@ -37,16 +42,65 @@ def test_write_report_tree_creates_files(tmp_path):
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_save_reports_explicit_path(tmp_path):
|
||||
# Unbound: with an explicit save_path, the method doesn't touch self/config.
|
||||
out = TradingAgentsGraph.save_reports(None, _state(), "AAPL", save_path=tmp_path)
|
||||
graph = SimpleNamespace(run_settings=lambda: SETTINGS)
|
||||
out = TradingAgentsGraph.save_reports(graph, _state(), "AAPL", save_path=tmp_path)
|
||||
assert (tmp_path / "complete_report.md").exists()
|
||||
assert out == tmp_path / "complete_report.md"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_save_reports_defaults_under_results_dir(tmp_path):
|
||||
mock_self = SimpleNamespace(config={"results_dir": str(tmp_path)})
|
||||
mock_self = SimpleNamespace(config={"results_dir": str(tmp_path)}, run_settings=lambda: SETTINGS)
|
||||
out = TradingAgentsGraph.save_reports(mock_self, _state(), "AAPL")
|
||||
assert out.exists()
|
||||
assert out.parent.parent.name == "reports" # results_dir/reports/AAPL_<stamp>/...
|
||||
assert out.parent.name.startswith("AAPL_")
|
||||
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_report_names_the_analysis_date_and_what_produced_it(tmp_path):
|
||||
state = dict(_state(), trade_date="2026-09-23")
|
||||
|
||||
header = write_report_tree(state, "NVDA", tmp_path, settings=SETTINGS).read_text().split("## ")[0]
|
||||
|
||||
assert "Analysis date: 2026-09-23" in header
|
||||
assert "TradingAgents 0.5.2" in header
|
||||
assert "openai, deep gpt-6-sol, quick gpt-6-luna" in header
|
||||
assert "Analysts: market, news" in header
|
||||
assert "research debate rounds 1, risk debate rounds 2" in header
|
||||
assert "core_stock_apis yfinance" in header
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_run_settings_record_the_run_without_endpoints_or_paths():
|
||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||
|
||||
graph = object.__new__(TradingAgentsGraph)
|
||||
graph.selected_analysts = ("market", "news")
|
||||
graph.config = {"llm_provider": "openai", "deep_think_llm": "gpt-6-sol", "quick_think_llm": "gpt-6-luna",
|
||||
"max_debate_rounds": 1, "max_risk_discuss_rounds": 1, "output_language": "English",
|
||||
"data_vendors": {"core_stock_apis": "yfinance"}, "tool_vendors": {},
|
||||
"backend_url": "https://user:secret@relay.example/v1", "results_dir": "/home/me/results"}
|
||||
|
||||
settings = graph.run_settings()
|
||||
|
||||
assert settings["analysts"] == ["market", "news"]
|
||||
assert settings["deep_think_llm"] == "gpt-6-sol"
|
||||
assert "secret" not in str(settings) and "/home/me" not in str(settings)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_partial_settings_dict_still_writes_the_report(tmp_path):
|
||||
out = write_report_tree(_state(), "AAPL", tmp_path, settings={"llm_provider": "openai"})
|
||||
assert "openai" in out.read_text()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_run_settings_name_the_version_of_the_running_code():
|
||||
import tradingagents
|
||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||
|
||||
graph = object.__new__(TradingAgentsGraph)
|
||||
graph.selected_analysts, graph.config = ("market",), {}
|
||||
assert graph.run_settings()["version"] == tradingagents.__version__
|
||||
|
||||
Reference in New Issue
Block a user