Build an AI News Monitoring Agent with LangChain + wpnews (Python)
In this tutorial, we'll build an autonomous news monitoring agent that watches a list of AI companies, detects when coverage surges, and sends targeted Slack alerts. The agent uses wpnews's get_news_velocity (burst detection) and get_adaptive_context (smart context loading) to minimize API calls while staying responsive to breaking news.
/api/v1/news-velocity, fetches entity-specific context only when activity is elevated, and posts Slack alerts when new coverage appears.
Architecture overview
- Velocity gate — check
/api/v1/news-velocityfirst. If it's a quiet day, skip the heavy fetch. - Watchlist polling —
/api/v1/watchlist/digestreturns articles for all tracked entities in one call. - LLM summarization — use LangChain with Claude to summarize new articles and generate a Slack message.
- Checkpoint tracking — use
/api/v1/articles/since?ts=…to only fetch articles newer than the last check.
Setup
pip install langchain langchain-anthropic requests slack-sdk
import os
WPNEWS_KEY = os.environ["WPNEWS_API_KEY"]
ANTHROPIC_KEY = os.environ["ANTHROPIC_API_KEY"]
SLACK_TOKEN = os.environ["SLACK_BOT_TOKEN"]
SLACK_CHANNEL = "#ai-news-alerts"
WPNEWS_BASE = "https://api.wpnews.pro"
HEADERS = {"X-API-Key": WPNEWS_KEY}
Step 1 — Add companies to your watchlist
Do this once (or via the dashboard at wpnews.pro/dashboard):
import requests
entities = ["OpenAI", "Anthropic", "Google DeepMind", "Mistral AI", "xAI"]
for entity in entities:
requests.post(
f"{WPNEWS_BASE}/api/v1/watchlist/items",
headers=HEADERS,
json={"type": "entity", "value": entity, "label": entity},
)
Step 2 — The monitoring loop
import time, json, requests
from datetime import datetime, timezone
from langchain_anthropic import ChatAnthropic
from langchain.schema import HumanMessage
from slack_sdk import WebClient
slack = WebClient(token=SLACK_TOKEN)
llm = ChatAnthropic(model="claude-haiku-4-5-20251001", api_key=ANTHROPIC_KEY)
last_check_ts = datetime.now(timezone.utc).isoformat()
def check_and_alert():
global last_check_ts
# Gate 1: velocity check — skip heavy fetch on quiet days
vel = requests.get(f"{WPNEWS_BASE}/api/v1/news-velocity", headers=HEADERS).json()
if vel.get("is_quiet"):
print(f"Quiet day ({vel['velocity_ratio']:.1f}x baseline) — skipping")
return
# Gate 2: only new articles since last check
digest = requests.get(
f"{WPNEWS_BASE}/api/v1/watchlist/digest",
headers=HEADERS,
params={"hours": 1, "limit_per_item": 3},
).json()
new_articles = [
art for group in digest.get("items", [])
for art in group.get("articles", [])
if art.get("published_at", "") > last_check_ts
]
if not new_articles:
return
# LLM summary
article_text = "\n\n".join(
f"**{a['title']}** ({a.get('entity','')}) — {a.get('summary','')}"
for a in new_articles[:5]
)
response = llm.invoke([HumanMessage(
content=f"Summarize these AI news items in 2-3 sentences for a Slack alert:\n\n{article_text}"
)])
summary = response.content
# Send to Slack
burst_prefix = " ⚡ BURST" if vel.get("is_burst") else ""
slack.chat_postMessage(
channel=SLACK_CHANNEL,
text=f"*AI News Update{burst_prefix}* — {len(new_articles)} new articles\n{summary}",
)
last_check_ts = datetime.now(timezone.utc).isoformat()
print(f"Alert sent: {len(new_articles)} articles")
# Run every 15 minutes
while True:
try:
check_and_alert()
except Exception as e:
print(f"Error: {e}")
time.sleep(900) # 15 minutes
Key optimization: adaptive context
When the agent needs to answer questions about the news (not just alert), use adaptive context to avoid over-fetching:
ctx = requests.get(
f"{WPNEWS_BASE}/api/v1/adaptive-context",
headers=HEADERS
).json()
# ctx['mode'] is 'quiet' | 'normal' | 'surge'
# ctx['context_text'] is ready for system prompt injection
# ctx['tokens_approx'] tells you the budget used (50-400)
from langchain_anthropic import ChatAnthropic
from langchain.schema import SystemMessage, HumanMessage
llm = ChatAnthropic(model="claude-sonnet-4-6", api_key=ANTHROPIC_KEY)
response = llm.invoke([
SystemMessage(content=f"You are an AI news analyst. Context: {ctx['context_text']}"),
HumanMessage(content="What should our ML team pay attention to today?"),
])
Production tips
- Use
get_articles/since?ts=…instead of hours-based filtering for checkpoint-precise polling - Rate limit awareness: wpnews returns
X-RateLimit-Remainingheaders — check them in your loop - Free tier (1k/day): with 15-min polling + velocity gate, you'll use ~8-12 calls/hour = ~200/day — well within free tier
- Pro webhooks: instead of polling, use
POST /api/v1/webhooksto get push notifications when new articles appear (Pro tier)
Build your monitoring agent
Free tier includes 5-item watchlist. Pro (10k/day + 50 items + webhooks): $19/mo.
More from the blog
How to Add Real-Time News to GPT-4 Agents (2025 Guide)
Step-by-step guide to giving GPT-4, Claude, or any LLM live access to AI news using wpnews function calling tools. 2-lin…
Add Real-Time AI News to Claude Desktop in 30 Seconds (MCP)
Install the wpnews MCP server in Claude Desktop with one npx command. Claude gets 61 news tools — search, entity trackin…
Build a Breaking News Detector with LangGraph + wpnews (2025)
Step-by-step guide to building a LangGraph agent that polls /articles/hot every 30 minutes, detects breaking stories, an…
Give AutoGen Agents Real-Time News Intelligence (Python, 2025)
Tutorial: wire wpnews into a Microsoft AutoGen multi-agent system. One tool registration gives every agent in your group…
Build a CrewAI News Research Crew with Real-Time Data (Python, 2025)
Tutorial: build a CrewAI crew of specialized agents — NewsResearcher, Analyst, and Writer — that collaborate to produce …
Build a News Agent with Pydantic AI + wpnews (Python, 2025)
Tutorial: use Pydantic AI's type-safe tool system to build a structured news analyst agent. Returns typed Pydantic model…
Automate AI News Digests with n8n + wpnews (No-Code, 2025)
Build a no-code n8n workflow that fetches AI news every morning, filters by breaking stories, and posts a digest to Slac…
Build a Real-Time News Retriever with Haystack + wpnews (Python, 2025)
Tutorial: implement a custom Haystack component that fetches live AI news from wpnews and plugs it into any RAG pipeline…
Build a News Agent with Google ADK + wpnews (Python, 2025)
Tutorial: wire wpnews into Google Agent Development Kit (ADK) — Google's official multi-agent framework. Register 71 new…
Real-Time News Tools for smolagents (HuggingFace, Python, 2025)
Tutorial: add live AI news to HuggingFace smolagents with the @tool decorator. Use wpnews as a CodeAgent or ToolCallingA…