prebuilt.tldr2.tools¶
Tools for the News Research Agent.
This module defines all tools used by the news research agent for web searching, content extraction, and analysis operations.
Tools are implemented as Pydantic models with proper typing and documentation for use with LangChain’s tool system.
Examples
>>> from news_research.tools import web_search, extract_content
>>> results = web_search.invoke({"query": "AI news", "max_results": 5})
>>> content = extract_content.invoke({"url": "https://example.com/article"})
Note
All tools follow LangChain tool patterns and return structured data compatible with the agent’s models.
Functions¶
|
Analyze the relevance of an article to the research topic. |
|
Process multiple articles concurrently. |
|
Check the credibility rating of a news source. |
|
Extract full text content from a news article URL. |
|
Filter articles by publication date. |
|
Search for news articles using NewsAPI. |
Module Contents¶
- prebuilt.tldr2.tools.analyze_relevance(article_title: str, article_description: str, search_query: str, research_topic: str) Dict[str, Any]¶
Analyze the relevance of an article to the research topic.
This tool uses heuristics to score how relevant an article is to the research topic and search query.
- Parameters:
article_title – Title of the article
article_description – Brief description of the article
search_query – Query used to find the article
research_topic – Main topic being researched
- Returns:
Dictionary with relevance score and explanation
Note
This is a simplified heuristic. In production, this could use an LLM or more sophisticated NLP techniques.
- async prebuilt.tldr2.tools.batch_process_articles(urls: List[str], operation: str = 'extract', max_concurrent: int = 5) Dict[str, Any]¶
Process multiple articles concurrently.
This tool enables efficient batch processing of multiple articles for extraction or analysis operations.
- Parameters:
urls – List of article URLs to process
operation – Type of operation (‘extract’ or ‘analyze’)
max_concurrent – Maximum number of concurrent operations
- Returns:
Dictionary with results for each URL and summary statistics
Examples
>>> results = await batch_process_articles( ... urls=["url1", "url2", "url3"], ... operation="extract" ... )
- prebuilt.tldr2.tools.check_source_credibility(source_name: str) Dict[str, Any]¶
Check the credibility rating of a news source.
This tool provides credibility information about news sources based on a predefined list of ratings.
- Parameters:
source_name – Name of the news source to check
- Returns:
Dictionary with credibility score and details
Note
In production, this would connect to a media bias/credibility API
- prebuilt.tldr2.tools.extract_content(url: str, timeout: int = 10) Dict[str, Any]¶
Extract full text content from a news article URL.
This tool fetches the web page and extracts the main article content using BeautifulSoup.
- Parameters:
url – URL of the article to extract
timeout – Request timeout in seconds
- Returns:
Dictionary with extracted content and metadata
Examples
>>> content = extract_content("https://example.com/article") >>> print(f"Extracted {content['word_count']} words")
- prebuilt.tldr2.tools.filter_by_date(articles: List[Dict[str, Any]], days_ago: int = 7) List[Dict[str, Any]]¶
Filter articles by publication date.
This tool filters a list of articles to include only those published within the specified number of days.
- Parameters:
articles – List of article dictionaries with ‘published_at’ field
days_ago – Number of days to look back
- Returns:
Filtered list of articles
- prebuilt.tldr2.tools.web_search(query: str, max_results: int = 10, sources: str | None = None, from_date: str | None = None, to_date: str | None = None) Dict[str, Any]¶
Search for news articles using NewsAPI.
This tool searches for news articles based on the provided query and filters. It returns metadata about matching articles.
- Parameters:
query – Search query string
max_results – Maximum number of results to return
sources – Comma-separated list of news sources
from_date – Start date for search (YYYY-MM-DD)
to_date – End date for search (YYYY-MM-DD)
- Returns:
Dictionary containing article metadata and search info
Examples
>>> results = web_search("AI healthcare", max_results=5) >>> print(f"Found {results['total_results']} articles")