Skip to main content

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.

ToolName seen by the modelUse it for
GNewsSearchgnews_searchArticles about a topic, company, or person, filtered by language, country, and date, with historical data since 2020.
GNewsTopHeadlinesgnews_top_headlinesToday'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​

Finds the articles that match a query. It works like the Search endpoint.

NameTypeRequiredDefaultDescription
qstringYesNoneWhat to search for, with the query syntax (exact phrases, parentheses, AND, OR, NOT)
langstringNoAny2-letter language code, for example en
countrystringNoAny2-letter country code of the source, for example us
from_datestringNoNoneOldest publication date: YYYY-MM-DD or ISO 8601 (2026-10-01T08:30:00Z)
to_datestringNoNoneNewest publication date, same formats
sortbystringNopublishedAtpublishedAt (most recent first) or relevance

gnews_top_headlines​

Returns the current top headlines of a category. It works like the Top Headlines endpoint.

NameTypeRequiredDefaultDescription
categorystringNogeneralgeneral, world, nation, business, technology, entertainment, sports, science, or health
langstringNoAny2-letter language code, for example en
countrystringNoAny2-letter country code, for example us
qstringNoNoneOptional query the headlines must match

Options​

Both tools accept these keyword arguments when created, for example GNewsSearch(max_results=5, include_content=False).

NameTypeRequiredDefaultDescription
api_keystringNoGNEWS_API_KEYGNews API key
max_resultsintegerNo10Number of articles to return, from 1 to your plan's limit
include_contentbooleanNoTrueInclude 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).