feat(news): configurable fetch params via DEFAULT_CONFIG

Per-ticker article limit, global article limit, global lookback
window, and macro query list are now read from get_config()
instead of being hardcoded. Tool wrapper get_global_news passes
None defaults so config overrides flow through the LLM-tool path
too. Macro query defaults broadened from 4 US-centric strings to
5 covering Fed, S&P 500, geopolitics, ECB/BOJ/BOE, commodities.

#606 #558 #562
This commit is contained in:
Yijia-Xiao
2026-05-11 05:30:52 +00:00
parent 0fcf13624e
commit 384fe1a3d2
3 changed files with 42 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
from langchain_core.tools import tool from langchain_core.tools import tool
from typing import Annotated from typing import Annotated, Optional
from tradingagents.dataflows.interface import route_to_vendor from tradingagents.dataflows.interface import route_to_vendor
@tool @tool
@@ -23,16 +23,20 @@ def get_news(
@tool @tool
def get_global_news( def get_global_news(
curr_date: Annotated[str, "Current date in yyyy-mm-dd format"], curr_date: Annotated[str, "Current date in yyyy-mm-dd format"],
look_back_days: Annotated[int, "Number of days to look back"] = 7, look_back_days: Annotated[Optional[int], "Days to look back; omit to use the configured default"] = None,
limit: Annotated[int, "Maximum number of articles to return"] = 5, limit: Annotated[Optional[int], "Max articles to return; omit to use the configured default"] = None,
) -> str: ) -> str:
""" """
Retrieve global news data. Retrieve global news data.
Uses the configured news_data vendor. Uses the configured news_data vendor. Defaults for look_back_days and
limit come from DEFAULT_CONFIG (global_news_lookback_days,
global_news_article_limit); pass explicit values to override.
Args: Args:
curr_date (str): Current date in yyyy-mm-dd format curr_date (str): Current date in yyyy-mm-dd format
look_back_days (int): Number of days to look back (default 7) look_back_days (int): Number of days to look back; omit to inherit config
limit (int): Maximum number of articles to return (default 5) limit (int): Maximum number of articles to return; omit to inherit config
Returns: Returns:
str: A formatted string containing global news data str: A formatted string containing global news data
""" """

View File

@@ -1,9 +1,12 @@
"""yfinance-based news data fetching functions.""" """yfinance-based news data fetching functions."""
from typing import Optional
import yfinance as yf import yfinance as yf
from datetime import datetime from datetime import datetime
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from .config import get_config
from .stockstats_utils import yf_retry from .stockstats_utils import yf_retry
@@ -64,9 +67,10 @@ def get_news_yfinance(
Returns: Returns:
Formatted string containing news articles Formatted string containing news articles
""" """
article_limit = get_config()["news_article_limit"]
try: try:
stock = yf.Ticker(ticker) stock = yf.Ticker(ticker)
news = yf_retry(lambda: stock.get_news(count=20)) news = yf_retry(lambda: stock.get_news(count=article_limit))
if not news: if not news:
return f"No news found for {ticker}" return f"No news found for {ticker}"
@@ -106,27 +110,28 @@ def get_news_yfinance(
def get_global_news_yfinance( def get_global_news_yfinance(
curr_date: str, curr_date: str,
look_back_days: int = 7, look_back_days: Optional[int] = None,
limit: int = 10, limit: Optional[int] = None,
) -> str: ) -> str:
""" """
Retrieve global/macro economic news using yfinance Search. Retrieve global/macro economic news using yfinance Search.
Args: Args:
curr_date: Current date in yyyy-mm-dd format curr_date: Current date in yyyy-mm-dd format
look_back_days: Number of days to look back look_back_days: Number of days to look back. ``None`` falls back to
limit: Maximum number of articles to return ``global_news_lookback_days`` from the active config.
limit: Maximum number of articles to return. ``None`` falls back to
``global_news_article_limit`` from the active config.
Returns: Returns:
Formatted string containing global news articles Formatted string containing global news articles
""" """
# Search queries for macro/global news config = get_config()
search_queries = [ if look_back_days is None:
"stock market economy", look_back_days = config["global_news_lookback_days"]
"Federal Reserve interest rates", if limit is None:
"inflation economic outlook", limit = config["global_news_article_limit"]
"global markets trading", search_queries = config["global_news_queries"]
]
all_news = [] all_news = []
seen_titles = set() seen_titles = set()

View File

@@ -35,6 +35,21 @@ DEFAULT_CONFIG = {
"max_debate_rounds": 1, "max_debate_rounds": 1,
"max_risk_discuss_rounds": 1, "max_risk_discuss_rounds": 1,
"max_recur_limit": 100, "max_recur_limit": 100,
# News / data fetching parameters
# Increase for longer lookback strategies or to broaden macro coverage;
# decrease to reduce token usage in agent prompts.
"news_article_limit": 20, # max articles per ticker (ticker-news)
"global_news_article_limit": 10, # max articles for global/macro news
"global_news_lookback_days": 7, # macro news lookback window
# Search queries used by get_global_news for macro headlines. Extend or
# replace to broaden geographic / sector coverage.
"global_news_queries": [
"Federal Reserve interest rates inflation",
"S&P 500 earnings GDP economic outlook",
"geopolitical risk trade war sanctions",
"ECB Bank of England BOJ central bank policy",
"oil commodities supply chain energy",
],
# Data vendor configuration # Data vendor configuration
# Category-level configuration (default for all tools in category) # Category-level configuration (default for all tools in category)
"data_vendors": { "data_vendors": {