LangChain
This page shows you how to give LangChain and LangGraph agents news tools with langchain-gnews.
langchain-gnews gives LangChain (opens in a new tab) and LangGraph agents two tools built on GNews API.
Web search tools return the most relevant pages. These tools return dated news articles with their source, filterable
by language and country, including over past periods.
| Tool | Name seen by the model | Use it for |
|---|---|---|
GNewsSearch | gnews_search | Articles about a topic, company, or person, filtered by language, country, and date, with historical data since 2020. |
GNewsTopHeadlines | gnews_top_headlines | Today's top headlines, based on Google News rankings, by category, language, and country: news briefings, digests. |
Every tool call is one API request with your API key. It counts toward your daily quota, and your plan sets the articles per request, freshness, and historical data: see Article Availability.
Install
pip install langchain-gnews
Python 3.10+. The package depends on langchain-core 1.x and on the official Python SDK.
Sign up to get a free API key, then put it in the GNEWS_API_KEY environment variable, or
pass it to the tools with api_key="YOUR_API_KEY".
export GNEWS_API_KEY="YOUR_API_KEY"
Use with an agent
Requires langchain and a model integration, for example pip install langchain langchain-anthropic.
from langchain.agents import create_agent
from langchain_gnews import GNewsSearch, GNewsTopHeadlines
agent = create_agent("anthropic:claude-sonnet-5-5", tools=[GNewsSearch(), GNewsTopHeadlines()])
agent.invoke({"messages": [{"role": "user", "content": "Summarize this morning's top business headlines in the United States"}]})
The model picks the tool from its description: search for a topic or a period, headlines for a briefing.
Use directly
from langchain_gnews import GNewsSearch, GNewsTopHeadlines
GNewsSearch().invoke({"q": "AI", "lang": "en"})
GNewsTopHeadlines().invoke({"category": "business", "lang": "en"})
Both return {"total_articles": int, "articles": [...]}, each article with title, description, content, url,
source, and published_at.
Available tools
gnews_search
Finds the articles that match a query. It works like the Search endpoint.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
q | string | Yes | None | What to search for, with the query syntax (exact phrases, parentheses, AND, OR, NOT) |
lang | string | No | Any | 2-letter language code, for example en |
country | string | No | Any | 2-letter country code of the source, for example us |
from_date | string | No | None | Oldest publication date: YYYY-MM-DD or ISO 8601 (2026-10-01T08:30:00Z) |
to_date | string | No | None | Newest publication date, same formats |
sortby | string | No | publishedAt | publishedAt (most recent first) or relevance |
gnews_top_headlines
Returns the current top headlines of a category. It works like the Top Headlines endpoint.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
category | string | No | general | general, world, nation, business, technology, entertainment, sports, science, or health |
lang | string | No | Any | 2-letter language code, for example en |
country | string | No | Any | 2-letter country code, for example us |
q | string | No | None | Optional query the headlines must match |
Options
Both tools accept these keyword arguments when created, for example GNewsSearch(max_results=5, include_content=False).
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
api_key | string | No | GNEWS_API_KEY | GNews API key |
max_results | integer | No | 10 | Number of articles to return, from 1 to your plan's limit |
include_content | boolean | No | True | Include the article text (False saves tokens) |
API errors (invalid API key, daily quota used up, rate limit) are returned to the model as tool errors instead of raising, so the agent can tell the user or try again.
What your plan returns
The tools return what your plan allows: see Article Availability for historical data and freshness, JSON Response for truncated content, and the Pricing page for the plans.
Source code
The package is open source, in the langchain-gnews repository (opens in a new tab) on GitHub, and published on PyPI (opens in a new tab).