LangChain
This page shows you how to give LangChain and LangGraph agents news tools with langchain-gnews.
langchain-gnews gives LangChain 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 country and language, including over past periods.
| Tool | Name seen by the model | Use it for |
|---|---|---|
GNewsTopHeadlines | gnews_top_headlines | Today's top headlines, based on Google News rankings, by category, country, and language: news briefings, digests |
GNewsSearch | gnews_search | Articles about a topic, company, or person, filtered by language, country, and date, with historical data since 2020 |
Each tool call makes one API request with your API key: it counts toward your daily quota and follows your plan (articles per request, historical data, and freshness: 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=[GNewsTopHeadlines(), GNewsSearch()])
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: headlines for a briefing, search for a topic or a period.
Use directly
from langchain_gnews import GNewsSearch, GNewsTopHeadlines
GNewsTopHeadlines().invoke({"category": "business", "lang": "en"})
GNewsSearch().invoke({"q": "AI", "lang": "en"})
Both return {"total_articles": int, "articles": [...]}, each article with title, description, content, url,
source, and published_at.
Available tools
gnews_search
Searches articles by keyword, like the Search endpoint.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
q | string | Yes | None | What to search for, with the query syntax (quotes, AND, OR, NOT, parentheses) |
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, ISO 8601, for example 2025-03-01. The archive starts in 2020 |
to_date | string | No | None | Newest publication date, ISO 8601 |
sortby | string | No | publishedAt | publishedAt (most recent first) or relevance |
gnews_top_headlines
Gets the top headlines of a category, 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 | Articles per request, up to the limit of your plan |
include_content | boolean | No | True | Include the article text. Set to False to save tokens |
API errors (invalid API key, quota reached, 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 on GitHub, and published on PyPI.