feat(market): verified market-data snapshot to ground numeric claims

The market analyst could confabulate exact figures — citing a Bollinger
band or a "historically validated bounce" the data doesn't support (#830).
Add a deterministic get_verified_market_snapshot tool (latest OHLCV row,
common indicators, recent closes) the analyst must consult and treat as
the source of truth for any exact price/indicator claim, and instruct it
not to assert historical validation or support bounces without tool-backed
dates and prices.

#830
This commit is contained in:
Yijia-Xiao committed 2026-05-31 01:58:32 +00:00
1 parent e80636fc0e
commit 47cbb321fe
5 files changed
+232 -1

No files matched your search

@@ -4,6 +4,7 @@ from tradingagents.agents.utils.agent_utils import (
get_indicators,
get_language_instruction,
get_stock_data,
get_verified_market_snapshot,
)
from tradingagents.dataflows.config import get_config
@@ -17,6 +18,7 @@ def create_market_analyst(llm):
tools = [
get_stock_data,
get_indicators,
get_verified_market_snapshot,
]
system_message = (
@@ -44,7 +46,11 @@ Volatility Indicators:
Volume-Based Indicators:
- vwma: VWMA: A moving average weighted by volume. Usage: Confirm trends by integrating price action with volume data. Tips: Watch for skewed results from volume spikes; use in combination with other volume analyses.
- Select indicators that provide diverse and complementary information. Avoid redundancy (e.g., do not select both rsi and stochrsi). Also briefly explain why they are suitable for the given market context. When you tool call, please use the exact name of the indicators provided above as they are defined parameters, otherwise your call will fail. Please make sure to call get_stock_data first to retrieve the CSV that is needed to generate indicators. Then use get_indicators with the specific indicator names. Write a very detailed and nuanced report of the trends you observe. Provide specific, actionable insights with supporting evidence to help traders make informed decisions."""
- Select indicators that provide diverse and complementary information. Avoid redundancy (e.g., do not select both rsi and stochrsi). Also briefly explain why they are suitable for the given market context. When you tool call, please use the exact name of the indicators provided above as they are defined parameters, otherwise your call will fail. Please make sure to call get_stock_data first to retrieve the CSV that is needed to generate indicators. Then use get_indicators with the specific indicator names.
Before writing the final report, call get_verified_market_snapshot for this ticker and the current date, and treat it as the source of truth for any exact OHLCV, price-level, or indicator-value claim. If another tool's output conflicts with the verified snapshot, flag the discrepancy rather than inventing a reconciled number. Do not claim historical validation, support/resistance bounces, or exact percentage moves unless they are directly supported by tool output with concrete dates and prices.
Write a very detailed and nuanced report of the trends you observe. Provide specific, actionable insights with supporting evidence to help traders make informed decisions."""
+ """ Make sure to append a Markdown table at the end of the report to organize key points in the report, organized and easy to read."""
+ get_language_instruction()
)
@@ -23,6 +23,9 @@ from tradingagents.agents.utils.news_data_tools import (
get_insider_transactions,
get_global_news
)
from tradingagents.agents.utils.market_data_validation_tools import (
get_verified_market_snapshot
)
logger = logging.getLogger(__name__)
@@ -0,0 +1,23 @@
from typing import Annotated
from langchain_core.tools import tool
from tradingagents.dataflows.market_data_validator import build_verified_market_snapshot
@tool
def get_verified_market_snapshot(
symbol: Annotated[str, "ticker symbol of the company"],
curr_date: Annotated[str, "the current trading date, YYYY-mm-dd"],
look_back_days: Annotated[
int, "number of recent trading rows to include for sanity-checking"
] = 30,
) -> str:
"""Deterministic verification snapshot for exact market-data claims.
Returns the latest OHLCV row on or before curr_date, common technical
indicators, and recent closes. Call this before making exact claims about
price levels, Bollinger bands, RSI, MACD, moving averages, support /
resistance, or historical comparisons, and treat it as the source of truth.
"""
return build_verified_market_snapshot(symbol, curr_date, look_back_days)