TradingAgents: Multi-Agents LLM Financial Trading Framework
fix(agents): keep the labelled rating lines in English in every output language (#1435)
Yijia-Xiao540ea8ca7fac
diff --git a/tests/test_i18n_coverage.py b/tests/test_i18n_coverage.pyindex e101dd1df..4a989302c 100644--- a/tests/test_i18n_coverage.py+++ b/tests/test_i18n_coverage.py@@ -46,6 +46,15 @@ class TestLanguageInstruction:assert "中文" in outassert "entire response" in out+ def test_the_labelled_lines_stay_as_the_format_gives_them(self):+ # The rating is read from its "**Rating**:" line; a translated label+ # leaves the reader a translated negation ("不建议卖出 (Sell)") to find+ # instead, and a Buy reads as Sell (#1435).+ from tradingagents.dataflows.config import set_config+ set_config({"output_language": "中文"})+ out = get_language_instruction()+ assert "**Rating**:" in out and "FINAL TRANSACTION PROPOSAL" in out+@pytest.mark.unit@pytest.mark.parametrize("rel", REPORT_AGENTS)diff --git a/tradingagents/agents/context.py b/tradingagents/agents/context.pyindex fd6a77169..2ff9122a5 100644--- a/tradingagents/agents/context.py+++ b/tradingagents/agents/context.py@@ -25,7 +25,14 @@ def get_language_instruction() -> str:lang = get_config().get("output_language", "English")if lang.strip().lower() == "english":return ""- return f" Write your entire response in {lang}."+ # The labelled lines are read by the program, so they keep their English+ # label and value: a translated rating line leaves the reader prose to+ # search, where a negated rating ("not a Sell") reads as the call (#1435).+ return (+ f" Write your entire response in {lang}, except the labelled lines the format"+ f" asks for (the \"**Rating**:\" line, \"FINAL TRANSACTION PROPOSAL:\"):"+ f" keep their label and value in English, exactly as specified."+ )def opponent_argument_or_opening(text: str, opponent: str) -> str: