Skip to content
Python

fix(agents): give a past run the company's current name only, as an identifier

Yijia-Xiaob99b843415ca
diff --git a/tests/test_undated_tools_as_of.py b/tests/test_undated_tools_as_of.py
index 6af796ae6..3252f928a 100644
--- a/tests/test_undated_tools_as_of.py
+++ b/tests/test_undated_tools_as_of.py
@@ -93,19 +93,20 @@ def test_trade_date_is_injected_not_model_visible(tool):
# --- the instrument's identity -------------------------------------------------
@pytest.mark.unit
-def test_a_historical_run_is_told_the_identity_is_current(monkeypatch):
- """The company name, sector and industry come from today's vendor profile.
- They are usually right for a past date, but a company that renamed or was
- reclassified since would read wrong, and every agent is told to anchor to
- this identity, so the run has to know which date it describes."""
+def test_a_historical_run_gets_the_current_name_only_as_an_identifier(monkeypatch):
+ """The profile is today's. The name still tells the company apart from others
+ (#814), so a past run keeps it, marked as today's; a sector, industry or
+ exchange that may not have held on the run's date is not given."""
from tradingagents.agents.context import build_instrument_context
identity = {"company_name": "Example Corp", "sector": "Technology",
"industry": "Software", "exchange": "NMS"}
historical = build_instrument_context("EXMP", "stock", identity, trade_date="2024-03-14")
- assert "Example Corp" in historical
- assert "2024-03-14" in historical and "today" in historical.lower()
+ assert "Example Corp" in historical and "current name" in historical
+ assert "2024-03-14" in historical
+ for later in ("Technology", "Software", "NMS"):
+ assert later not in historical
@pytest.mark.unit
@@ -116,7 +117,7 @@ def test_a_current_run_is_not_cluttered_with_a_vintage_note(monkeypatch):
today = build_instrument_context("EXMP", "stock", {"company_name": "Example Corp"},
trade_date=get_current_date())
assert "Example Corp" in today
- assert "resolved today" not in today.lower()
+ assert "current name" not in today
@pytest.mark.unit
diff --git a/tradingagents/agents/context.py b/tradingagents/agents/context.py
index 2ff9122a5..87ec7a433 100644
--- a/tradingagents/agents/context.py
+++ b/tradingagents/agents/context.py
@@ -119,9 +119,10 @@ def build_instrument_context(
than pattern-matching the price chart to a wrong one (#814).
That profile carries no historical vintage: it describes the company today.
- For a run dated earlier, the context says so, since a company that has since
- renamed or been reclassified would otherwise anchor the whole graph to an
- identity it did not have on the analysis date.
+ A run dated earlier gets the current name alone, as a way to tell the
+ company apart from others rather than as what it was called then; a sector,
+ industry or exchange it holds today is not given, since it may not have held
+ on the analysis date.
"""
is_crypto = asset_type == "crypto"
instrument_label = "asset" if is_crypto else "instrument"
@@ -131,11 +132,19 @@ def build_instrument_context(
"preserving any exchange suffix (e.g. `.TO`, `.L`, `.HK`, `.T`, `-USD`)."
)
+ identity = identity or {}
+ name = identity.get("company_name") or identity.get("name")
+ label = "Name" if is_crypto else "Company"
details = []
- if identity:
- name = identity.get("company_name") or identity.get("name")
+ if trade_date and str(trade_date) < get_current_date():
if name:
- details.append(f"{'Name' if is_crypto else 'Company'}: {name}")
+ details.append(
+ f"{label}: {name} (its current name, given only to identify it; "
+ f"on {trade_date} it may have been named differently)"
+ )
+ else:
+ if name:
+ details.append(f"{label}: {name}")
sector, industry = identity.get("sector"), identity.get("industry")
if sector and industry:
details.append(f"Business classification: {sector} / {industry}")
@@ -152,13 +161,6 @@ def build_instrument_context(
"Do not substitute a different company or ticker unless a tool "
"result explicitly disproves this resolved identity."
)
- today = get_current_date()
- if trade_date and str(trade_date) < today:
- context += (
- f" This identity is how the vendor describes the instrument today, "
- f"not necessarily on {trade_date}: a name or classification changed "
- f"since then would read as the current one."
- )
if is_crypto:
context += (