Newspaper Agent

News article extraction tools for AI agents.

python
from praisonaiagents import Agent
from praisonaiagents import extract_article

agent = Agent(
    name="News Reader",
    instructions="Extract and summarise news articles from URLs.",
    tools=[extract_article],
)
agent.start("Summarise the main points from this article URL")

The user pastes a news link; the agent extracts article text and returns a brief summary.

Diagram

Input

Agent

Tool

Output

Diagram
Newspaper AgentAgentUserNewspaper AgentAgentUserRequestProcess requestResultResponse

Newspaper Tools

Use Newspaper Tools to extract and analyze news articles with AI agents.

  1. Install Dependencies

    First, install the required packages:

    bash
    pip install praisonaiagents praisonai-tools newspaper3k
  2. Import Components

    Import the necessary components:

    python
    from praisonaiagents import Agent, Task, AgentTeam
    from praisonai_tools import get_article, get_news_sources, get_articles_from_source, get_trending_topics
  3. Create Agent

    Create a news agent:

    python
    news_agent = Agent(
        name="NewsAgent",
        role="News Analyst",
        goal="Collect and analyze news articles from various sources.",
        backstory="Expert in news gathering and content analysis.",
        tools=[get_article, get_news_sources, get_articles_from_source, get_trending_topics],
        reflection=False
    )
  4. Define Task

    Define the news task:

    python
    news_task = Task(
        description="Analyze news articles about 'AI developments' from major tech news sources.",
        expected_output="Summary of key AI developments with source articles.",
        agent=news_agent,
        name="ai_news"
    )
  5. Run Agent

    Initialize and run the agent:

    python
    agents = AgentTeam(
        agents=[news_agent],
        tasks=[news_task],
        process="sequential"
    )
    agents.start()

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

Available Functions

python
from praisonai_tools import get_article
from praisonai_tools import get_news_sources
from praisonai_tools import get_articles_from_source
from praisonai_tools import get_trending_topics

Examples

Basic News Agent

python
from praisonaiagents import Agent, Task, AgentTeam
from praisonai_tools import get_article, get_news_sources, get_articles_from_source, get_trending_topics

# Create news agent
news_agent = Agent(
    name="NewsExpert",
    role="News Analyst",
    goal="Gather and analyze news content efficiently.",
    backstory="Expert in news analysis and content curation.",
    tools=[get_article, get_news_sources, get_articles_from_source, get_trending_topics],
    reflection=False
)

# Define news task
news_task = Task(
    description="Analyze tech news trends.",
    expected_output="Tech news analysis report.",
    agent=news_agent,
    name="tech_news_analysis"
)

# Run agent
agents = AgentTeam(
    agents=[news_agent],
    tasks=[news_task],
    process="sequential"
)
agents.start()

Advanced News Analysis with Multiple Agents

python
from praisonaiagents import Agent, Task, AgentTeam
from praisonai_tools import get_article, get_news_sources, get_articles_from_source, get_trending_topics

# Create news collection agent
collector_agent = Agent(
    name="Collector",
    role="News Collector",
    goal="Gather comprehensive news coverage.",
    tools=[get_article, get_news_sources, get_articles_from_source, get_trending_topics],
    reflection=False
)

# Create analysis agent
analysis_agent = Agent(
    name="Analyzer",
    role="Content Analyst",
    goal="Analyze news content and identify trends.",
    backstory="Expert in news analysis and trend identification.",
    reflection=False
)

# Define tasks
collection_task = Task(
    description="Collect news articles about renewable energy developments.",
    agent=collector_agent,
    name="energy_news"
)

analysis_task = Task(
    description="Analyze the articles and identify key trends and breakthroughs.",
    agent=analysis_agent,
    name="news_analysis"
)

# Run agents
agents = AgentTeam(
    agents=[collector_agent, analysis_agent],
    tasks=[collection_task, analysis_task],
    process="sequential"
)
agents.start()

Best Practices

Agent Configuration

Configure agents with clear news focus:

python
from praisonai_tools import get_article, get_news_sources, get_articles_from_source, get_trending_topics

Agent(
    name="NewsAnalyst",
    role="News Specialist",
    goal="Analyze news content effectively",
    tools=[get_article, get_news_sources, get_articles_from_source, get_trending_topics]
)
Task Definition

Define specific news objectives:

python
Task(
    description="Analyze tech news from major sources for AI developments",
    expected_output="Trend analysis with key findings"
)

Common Patterns

News Monitoring

python
from praisonaiagents import Agent, Task, AgentTeam
from praisonai_tools import get_article, get_news_sources, get_articles_from_source, get_trending_topics

# News monitor agent
monitor = Agent(
    name="Monitor",
    role="News Monitor",
    tools=[get_article, get_news_sources, get_articles_from_source, get_trending_topics]
)

# Analysis agent
analyst = Agent(
    name="Analyst",
    role="News Analyst"
)

# Define tasks
monitor_task = Task(
    description="Monitor tech news sources",
    agent=monitor
)

analysis_task = Task(
    description="Analyze news trends",
    agent=analyst
)

# Run workflow
agents = AgentTeam(
    agents=[monitor, analyst],
    tasks=[monitor_task, analysis_task]
)

Related