fix(graph): resolve instrument identity to stop wrong-company hallucination
Agents had no ground-truth ticker→company mapping, so the market analyst could pattern-match a price chart to the wrong company (e.g. TOTDY read as "TotalEnergies"), and every downstream agent inherited the bad framing. Resolve identity once at run start via a cached, fail-open yfinance lookup and inject company/sector/exchange into the shared instrument context that all twelve agents consume, with an explicit do-not-substitute instruction. Resolution runs on both the propagate() and CLI entry points. Also replaces the bare "Continue" message-clear placeholder, which some OpenAI-compatible providers interpreted as the user task, with a context-anchored placeholder carrying the resolved identity and date. #814 #888
This commit is contained in:
1 parent
61522e103e
commit
d7b40a2a5c
18 files changed
+390
-44
No files matched your search
@@ -1,6 +1,6 @@
|
||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
from tradingagents.agents.utils.agent_utils import (
|
||||
build_instrument_context,
|
||||
get_instrument_context_from_state,
|
||||
get_balance_sheet,
|
||||
get_cashflow,
|
||||
get_fundamentals,
|
||||
@@ -14,7 +14,7 @@ from tradingagents.dataflows.config import get_config
|
||||
def create_fundamentals_analyst(llm):
|
||||
def fundamentals_analyst_node(state):
|
||||
current_date = state["trade_date"]
|
||||
instrument_context = build_instrument_context(state["company_of_interest"])
|
||||
instrument_context = get_instrument_context_from_state(state)
|
||||
|
||||
tools = [
|
||||
get_fundamentals,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
from tradingagents.agents.utils.agent_utils import (
|
||||
build_instrument_context,
|
||||
get_instrument_context_from_state,
|
||||
get_indicators,
|
||||
get_language_instruction,
|
||||
get_stock_data,
|
||||
@@ -12,10 +12,7 @@ def create_market_analyst(llm):
|
||||
|
||||
def market_analyst_node(state):
|
||||
current_date = state["trade_date"]
|
||||
asset_type = state.get("asset_type", "stock")
|
||||
instrument_context = build_instrument_context(
|
||||
state["company_of_interest"], asset_type
|
||||
)
|
||||
instrument_context = get_instrument_context_from_state(state)
|
||||
|
||||
tools = [
|
||||
get_stock_data,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
from tradingagents.agents.utils.agent_utils import (
|
||||
build_instrument_context,
|
||||
get_instrument_context_from_state,
|
||||
get_global_news,
|
||||
get_language_instruction,
|
||||
get_news,
|
||||
@@ -13,9 +13,7 @@ def create_news_analyst(llm):
|
||||
current_date = state["trade_date"]
|
||||
asset_type = state.get("asset_type", "stock")
|
||||
asset_label = "company" if asset_type == "stock" else "asset"
|
||||
instrument_context = build_instrument_context(
|
||||
state["company_of_interest"], asset_type
|
||||
)
|
||||
instrument_context = get_instrument_context_from_state(state)
|
||||
|
||||
tools = [
|
||||
get_news,
|
||||
|
||||
@@ -23,7 +23,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
from tradingagents.agents.utils.agent_utils import (
|
||||
build_instrument_context,
|
||||
get_instrument_context_from_state,
|
||||
get_language_instruction,
|
||||
get_news,
|
||||
)
|
||||
@@ -47,7 +47,7 @@ def create_sentiment_analyst(llm):
|
||||
ticker = state["company_of_interest"]
|
||||
end_date = state["trade_date"]
|
||||
start_date = _seven_days_back(end_date)
|
||||
instrument_context = build_instrument_context(ticker)
|
||||
instrument_context = get_instrument_context_from_state(state)
|
||||
|
||||
# Pre-fetch all three sources. Each fetcher degrades gracefully and
|
||||
# returns a string (no exceptions surface from here), so the LLM
|
||||
|
||||
Reference in new issue
Block a user