mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-27 23:12:39 +03:00
fix(agents): say when the resolved identity is today's, not the run date's
- the vendor profile has no historical vintage, and every agent is told to anchor to it
This commit is contained in:
@@ -48,6 +48,8 @@ __all__ = [
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from tradingagents.dataflows.utils import get_current_date # noqa: E402
|
||||
|
||||
|
||||
def get_language_instruction() -> str:
|
||||
"""Return a prompt instruction for the configured output language.
|
||||
@@ -137,6 +139,7 @@ def build_instrument_context(
|
||||
ticker: str,
|
||||
asset_type: str = "stock",
|
||||
identity: Mapping[str, str] | None = None,
|
||||
curr_date: str | None = None,
|
||||
) -> str:
|
||||
"""Describe the exact instrument so agents preserve identity and ticker.
|
||||
|
||||
@@ -144,6 +147,11 @@ def build_instrument_context(
|
||||
:func:`resolve_instrument_identity`), the company name and business
|
||||
classification are injected so agents anchor to the real company rather
|
||||
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.
|
||||
"""
|
||||
is_crypto = asset_type == "crypto"
|
||||
instrument_label = "asset" if is_crypto else "instrument"
|
||||
@@ -174,6 +182,13 @@ 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 curr_date and str(curr_date) < today:
|
||||
context += (
|
||||
f" This identity is how the vendor describes the instrument today "
|
||||
f"({today}), not necessarily on {curr_date}: a name or "
|
||||
f"classification changed since then would read as the current one."
|
||||
)
|
||||
|
||||
if is_crypto:
|
||||
context += (
|
||||
|
||||
@@ -393,7 +393,8 @@ class TradingAgentsGraph:
|
||||
if updates:
|
||||
self.memory_log.batch_update_with_outcomes(updates)
|
||||
|
||||
def resolve_instrument_context(self, ticker: str, asset_type: str = "stock") -> str:
|
||||
def resolve_instrument_context(self, ticker: str, asset_type: str = "stock",
|
||||
curr_date: str | None = None) -> str:
|
||||
"""Resolve ticker identity once and return the full instrument context.
|
||||
|
||||
Deterministic yfinance lookup (cached, fail-open) injected into a
|
||||
@@ -403,7 +404,7 @@ class TradingAgentsGraph:
|
||||
graph regardless of entry point.
|
||||
"""
|
||||
identity = resolve_instrument_identity(ticker)
|
||||
return build_instrument_context(ticker, asset_type, identity)
|
||||
return build_instrument_context(ticker, asset_type, identity, curr_date)
|
||||
|
||||
def _memory_as_of(self, trade_date) -> str | None:
|
||||
"""Point-in-time cutoff for past-context lessons (#1251).
|
||||
@@ -551,7 +552,7 @@ class TradingAgentsGraph:
|
||||
past_context=self.memory_log.get_past_context(
|
||||
company_name, as_of=self._memory_as_of(trade_date)
|
||||
),
|
||||
instrument_context=self.resolve_instrument_context(company_name, asset_type),
|
||||
instrument_context=self.resolve_instrument_context(company_name, asset_type, trade_date),
|
||||
portfolio_context=portfolio.render(company_name) if portfolio is not None else "",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user