From d53b076b7a8cbf0458fb3adb948445b54c8069b6 Mon Sep 17 00:00:00 2001 From: Yijia-Xiao Date: Thu, 1 Oct 2026 05:46:09 +0000 Subject: [PATCH] feat(reports): name the rating in the report header - the header lists the run's rating, REVIEW when the decision has none --- tests/test_reporting.py | 13 +++++++++++++ tradingagents/reporting.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/tests/test_reporting.py b/tests/test_reporting.py index 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__ + + +@pytest.mark.unit +@pytest.mark.parametrize("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 header diff --git a/tradingagents/reporting.py b/tradingagents/reporting.py index 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 datetime from 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