
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)

News Agent
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.
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 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.
The run above used 2 workers: predicted 7.0 s, measured 7.03 s.

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)

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)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.
One article goes in; a summary, a category and the time taken come out, and the time stays within its expected bounds.
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