Start a project

News Agent

2025 · AI agents

Six articles,read at once,in seven seconds.

An agent that fetches news articles, then summarizes and sorts each one by topic, with the people and tools it mentions.

It is built around one idea: waiting on the network and thinking on the processor are different kinds of work, so each gets its own tool, and they never wait on each other.

Year
2025
Role
Design, build
Stack
Python · asyncio · Pydantic
Source
GitHub
01 · The run

One command, start to finish.

A real run, recorded in the terminal. The agent does the six articles its way, then does them again one at a time, and times both.

  • The agent's way7.03seconds
  • One at a time18.01seconds
  • Faster2.56times
02 · The race

Where the time goes.

The same run as a timeline: each article takes 1 s to fetch and 2 s to analyse. Change how many processor workers the agent gets and watch its side shrink.

2 workersFetch · waitingAnalyse · thinking
One at a time18.0 s
The agent7.0 s · 2.57× faster

The run above used 2 workers: predicted 7.0 s, measured 7.03 s.

03 · Two kinds of work

Waiting and thinking.

Six beams of light carry six articles side by side into a glass gateway, with a faint single lane behind them
Waiting · the network

Ask for all six at once.

Fetching is mostly waiting for a reply. asyncio sends every request together and waits for them as one, so six fetches take the time of one.

fetch_tasks = [fetch(url) for url in urls]
raw = await asyncio.gather(*fetch_tasks)
Four processor chips each read an article and send up a short summary at the same time
Thinking · the processor

Give each core its own article.

Reading and summarizing keeps the processor busy. A process pool runs it on separate cores, and the agent hands work over without blocking itself.

return await loop.run_in_executor(
    executor, analyze, raw_article, analysis_time)
04 · Built to swap

Typed at every step, swappable at the core.

Every hand-off is a Pydantic model, so bad data stops at the border. How an article is analysed is a strategy class: a real model can replace the stand-in without touching the agent.

  1. In

    RawArticleData

    url
    str
    content
    str · full text
    fetch_time
    float
  2. Out

    ArticleAnalysisResult

    summary
    str
    category
    str
    entities
    list[str]
    analysis_time
    float
  3. Report

    NewsAgentReport

    results
    list[ArticleAnalysisResult]
    total_articles
    int
    total_time_taken
    float
  • Settings from .envWorkers, delays and timeouts load through pydantic-settings, with safe defaults.
  • A pool that closes itselfThe process pool lives inside an async context manager and always shuts down, even on errors.
  • One strategy, more to comeSummarize-and-categorize is one class behind a small interface; a new one drops in beside it.
05 · Tests

The speed-up is tested.

6Articles
2Workers
18.01Seconds, one at a time
7.03Seconds, the agent
  • Test · one article

    The whole path works.

    One article goes in; a summary, a category and the time taken come out, and the time stays within its expected bounds.

  • Test · many articles

    Faster, or it fails.

    Several articles must finish at least 30% faster than one at a time, and close to the predicted time, neither slower nor suspiciously quicker.

Built in Python with asyncio, a process pool, Pydantic and pytest.

A learning project · the articles are simulated, the concurrency is real

More projects

All work