Skip to content
Python

feat(news): configurable fetch params via DEFAULT_CONFIG

Yijia-Xiao384fe1a3d2b5
diff --git a/tradingagents/agents/utils/news_data_tools.py b/tradingagents/agents/utils/news_data_tools.py
index 781e793c3..f503c4d3a 100644
--- a/tradingagents/agents/utils/news_data_tools.py
+++ b/tradingagents/agents/utils/news_data_tools.py
@@ -1,5 +1,5 @@
from langchain_core.tools import tool
-from typing import Annotated
+from typing import Annotated, Optional
from tradingagents.dataflows.interface import route_to_vendor
@tool
@@ -23,16 +23,20 @@ def get_news(
@tool
def get_global_news(
curr_date: Annotated[str, "Current date in yyyy-mm-dd format"],
- look_back_days: Annotated[int, "Number of days to look back"] = 7,
- limit: Annotated[int, "Maximum number of articles to return"] = 5,
+ look_back_days: Annotated[Optional[int], "Days to look back; omit to use the configured default"] = None,
+ limit: Annotated[Optional[int], "Max articles to return; omit to use the configured default"] = None,
) -> str:
"""
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:
curr_date (str): Current date in yyyy-mm-dd format
- look_back_days (int): Number of days to look back (default 7)
- limit (int): Maximum number of articles to return (default 5)
+ look_back_days (int): Number of days to look back; omit to inherit config
+ limit (int): Maximum number of articles to return; omit to inherit config
+
Returns:
str: A formatted string containing global news data
"""
diff --git a/tradingagents/dataflows/yfinance_news.py b/tradingagents/dataflows/yfinance_news.py
index dd1046f54..55c5d2512 100644
--- a/tradingagents/dataflows/yfinance_news.py
+++ b/tradingagents/dataflows/yfinance_news.py
@@ -1,9 +1,12 @@
"""yfinance-based news data fetching functions."""
+from typing import Optional
+
import yfinance as yf
from datetime import datetime
from dateutil.relativedelta import relativedelta
+from .config import get_config
from .stockstats_utils import yf_retry
@@ -64,9 +67,10 @@ def get_news_yfinance(
Returns:
Formatted string containing news articles
"""
+ article_limit = get_config()["news_article_limit"]
try:
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:
return f"No news found for {ticker}"
@@ -106,27 +110,28 @@ def get_news_yfinance(
def get_global_news_yfinance(
curr_date: str,
- look_back_days: int = 7,
- limit: int = 10,
+ look_back_days: Optional[int] = None,
+ limit: Optional[int] = None,
) -> str:
"""
Retrieve global/macro economic news using yfinance Search.
Args:
curr_date: Current date in yyyy-mm-dd format
- look_back_days: Number of days to look back
- limit: Maximum number of articles to return
+ look_back_days: Number of days to look back. ``None`` falls back to
+ ``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:
Formatted string containing global news articles
"""
- # Search queries for macro/global news
- search_queries = [
- "stock market economy",
- "Federal Reserve interest rates",
- "inflation economic outlook",
- "global markets trading",
- ]
+ config = get_config()
+ if look_back_days is None:
+ look_back_days = config["global_news_lookback_days"]
+ if limit is None:
+ limit = config["global_news_article_limit"]
+ search_queries = config["global_news_queries"]
all_news = []
seen_titles = set()
diff --git a/tradingagents/default_config.py b/tradingagents/default_config.py
index fa6d5742c..faa71f591 100644
--- a/tradingagents/default_config.py
+++ b/tradingagents/default_config.py
@@ -35,6 +35,21 @@ DEFAULT_CONFIG = {
"max_debate_rounds": 1,
"max_risk_discuss_rounds": 1,
"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
# Category-level configuration (default for all tools in category)
"data_vendors": {