Give your AI agent real-time market news (tool calling + RAG)
How to connect an LLM agent to live financial news: a tool definition for /v1/news, prompt patterns, and why short summaries beat raw articles in context.

Large language models don't know what happened in the market this morning. Their training data stops months ago, and web search results are noisy and slow. A news API gives an agent a clean, current, symbol-tagged view of the market it can query in one tool call.
Why structured news beats web search for agents
- Precision: filter by
tickers=NVDAinstead of hoping a search engine ranks the right pages. - Freshness: sources are polled every second, and each article has exact timestamps.
- Token budget: a 2-sentence
summaryplus title is roughly 60 tokens. A scraped article can be 2,000. - Grounding: every item has a source and URL the model can cite.
1. Define the tool
Expose a narrow tool. Agents do better with a few clear parameters than with every filter we support.
{
"type": "function",
"function": {
"name": "get_market_news",
"description": "Get recent stock news. Use for questions about why a stock moved, or what's happening with a company.",
"parameters": {
"type": "object",
"properties": {
"tickers": {
"type": "string",
"description": "Comma-separated stock tickers, e.g. 'AAPL,MSFT'"
},
"category": {
"type": "string",
"enum": [
"stocks"
],
"description": "stocks"
},
"q": {
"type": "string",
"description": "Optional keyword or phrase"
},
"hours": {
"type": "integer",
"description": "Look-back window in hours (default 24)"
}
}
}
}
}2. Implement it
Return compact records. Drop fields the model doesn't need, and keep the URL for citations.
import os
from datetime import datetime, timedelta, timezone
import requests
def get_market_news(tickers=None, category="stocks", q=None, hours=24):
params = {"limit": 15, "from": (datetime.now(timezone.utc) - timedelta(hours=hours)).isoformat()}
for k, v in {"tickers": tickers, "category": category, "q": q}.items():
if v:
params[k] = v
r = requests.get(
"https://api.marketnewsapi.com/v1/news",
params=params,
headers={"Authorization": f"Bearer {os.environ['MARKETNEWSAPI_KEY']}"},
timeout=10,
)
r.raise_for_status()
return [
{
"time": a["published_at"],
"title": a["title"],
"summary": a["summary"] or a["snippet"],
"symbols": a["tickers"],
"source": a["source"]["name"],
"url": a["url"],
}
for a in r.json()["data"]
]Try it for 7 days. Signup starts Pro. A card is required. Real-time REST, WebSocket, and MCP, with no request cap. After that it's $15/month, or Free if you stop.
3. Prompt for grounded answers
You are a markets assistant. When a question depends on recent events, call get_market_news first.
Answer only from the returned articles. Cite sources inline as [Source](url).
If the articles don't explain a move, say so instead of guessing. Never give investment advice.4. Or index it for RAG
For research assistants that need weeks of context, stream articles into your vector store as they arrive (WebSocket all or ticker: channels) and embed title + summary. Store tickers, category, and published_at as metadata, so retrieval can filter before ranking by similarity.
5. Let agents discover the API
Agents and coding assistants can read our machine-readable docs directly: the OpenAPI 3.1 spec, llms.txt and pricing.md. Point your agent framework's OpenAPI importer at the spec to generate all tools at once.