Python
feat(reports): name the rating in the report header
Yijia-Xiaod53b076b7a8c
diff --git a/tests/test_reporting.py b/tests/test_reporting.pyindex 1f634a89c..67fccef9b 100644--- a/tests/test_reporting.py+++ b/tests/test_reporting.py@@ -106,3 +106,16 @@ def test_run_settings_name_the_version_of_the_running_code():graph = object.__new__(TradingAgentsGraph)graph.selected_analysts, graph.config = ("market",), {}assert graph.run_settings()["version"] == tradingagents.__version__++[email protected]("decision, rating", [+ ("**Rating**: Overweight\n\nAdd on weakness.", "Overweight"),+ ("Add on weakness.", "REVIEW"), # no readable rating is said, not left out+])+def test_the_report_header_names_the_rating(tmp_path, decision, rating):+ state = dict(_state(), final_trade_decision=decision)++ header = write_report_tree(state, "NVDA", tmp_path, settings=SETTINGS).read_text().split("## ")[0]++ assert f"- Rating: {rating}" in headerdiff --git a/tradingagents/reporting.py b/tradingagents/reporting.pyindex 7d1802f8a..f1b4268ed 100644--- a/tradingagents/reporting.py+++ b/tradingagents/reporting.py@@ -9,12 +9,16 @@ run produces the same on-disk report tree a CLI run does.from datetime import datetimefrom pathlib import Path+from tradingagents.agents.rating import run_rating+def _header(ticker: str, final_state: dict, settings: dict | None) -> str:"""The report's title and what produced it: analysis date, version, models, analysts, vendors."""lines = [f"# Trading Analysis Report: {ticker}", ""]if final_state.get("trade_date"):lines.append(f"- Analysis date: {final_state['trade_date']}")+ if final_state.get("final_trade_decision"):+ lines.append(f"- Rating: {run_rating(final_state)}")lines.append(f"- Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")if settings:s = settings.get