Newspaper Agent
News article extraction tools for AI agents.
Prerequisites
- Python 3.10 or higher
- PraisonAI Agents package installed
newspaper3k
package installed
Newspaper Tools
Use Newspaper Tools to extract and analyze news articles with AI agents.
Install Dependencies
First, install the required packages:
Import Components
Import the necessary components:
Create Agent
Create a news agent:
Define Task
Define the news task:
Run Agent
Initialize and run the agent:
Understanding Newspaper Tools
What are Newspaper Tools?
Newspaper Tools provide news article processing capabilities for AI agents:
- Article extraction
- Source management
- Content analysis
- Trend detection
- Multi-language support
Key Components
News Agent
Create specialized news agents:
News Task
Define news tasks:
Process Types
Sequential or parallel processing:
Article Options
Customize article retrieval:
Available Functions
Function Details
get_article(url: str, language: str = ‘en’)
Extracts and parses news articles:
- Full text extraction
- Author detection
- Date parsing
- Image extraction
- NLP processing
get_news_sources(category: Optional[str] = None, language: str = ‘en’, country: Optional[str] = None)
Gets news sources by category:
- Category filtering
- Language support
- Country filtering
- Domain information
get_articles_from_source(source_url: str, limit: int = 10, language: str = ‘en’)
Gets recent articles from a source:
- Configurable limit
- Language support
- Full article parsing
- Error handling
get_trending_topics(sources: Optional[List[str]] = None, limit: int = 10, language: str = ‘en’)
Analyzes trending topics:
- Cross-source analysis
- Keyword extraction
- Customizable sources
- Topic ranking
Examples
Basic News Agent
Advanced News Analysis with Multiple Agents
Best Practices
Common Patterns
News Monitoring
Example Agent Configuration
Dependencies
The newspaper tools require the following Python packages:
- newspaper3k: For article extraction and parsing
- nltk: For NLP processing (automatically installed with newspaper3k)
These will be automatically installed when needed.
Error Handling
All functions include comprehensive error handling:
- Network errors
- Parsing errors
- Language errors
- Source availability errors
Errors are handled consistently:
- Success cases return the expected data type
- Error cases return a dict with an “error” key
- All errors are logged for debugging
Common Use Cases
- News Monitoring:
- Trend Analysis:
- Content Aggregation:
Was this page helpful?