cd /news/ai-agents/when-to-use-an-agent-and-when-a-chai… · home › topics › ai-agents › article
[ARTICLE · art-178650] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

When to use an agent and when a chain: notes from my research pipeline

A developer built a multi-agent AI research pipeline that searches the web, scrapes pages, writes a Markdown report and has a critic score it, deliberately using LangChain agents only for the two open-ended steps (search and read) and LCEL chains for the fixed steps (write and critique). The search agent, using a Tavily-backed web_search tool, picks queries and returns five sources, while the reader agent uses a BeautifulSoup scrape_url tool to pick two pages; tool outputs are capped at 300 characters per snippet, 1,500 per page and 2,500 overall to stay within token limits. The critic returns a Pydantic-structured score, and reports scoring below MIN_GOOD_SCORE = 7 get one rewrite, with a score of 0 reserved to signal a failed review rather than a bad report.

recommendation

Split pipelines by decision-making: give agents tools only for open-ended steps like search and page selection, and use fixed chains for writing and critique, capping tool output to avoid token limits.

more in playbook: Designing agent systems
by read4 min views9 publishedNov 30, 2026

My Multi-Agent AI Research System takes a topic, searches the web, reads the most useful pages, writes a Markdown report and then has a critic score it. If it scores below 7 out of 10, the report goes back for one rewrite. The agents, tools, pipeline and feedback loop are my work, with AI help in places; the Streamlit interface was built with AI help.

It's called multi-agent, but only two of its four steps are agents. That split was the main design decision, so this post is about how I made it.

The rule I followed: if the model needs to decide, use an agent; if the task is fixed, use a chain.

An agent, built with LangChain's create_agent, is given tools and chooses for itself whether to call them, which one, and how many times. A chain built with LCEL is a fixed sequence: prompt, then model, then parser, every time. This is how the README sums up the first three steps:

Step Built with Why
Search create_agent +web_search tool The LLM decides what and how many times to search
Read create_agent +scrape_url tool The LLM decides which URLs are worth reading
Write LCEL chain (`prompt \ model \

The critic is a chain too, with Pydantic structured output on the end. Writing a report from notes, or reviewing one, is the same job every time. Searching and reading are not: which queries to run, how many, and which pages are worth opening depend on the topic, so those two steps let the model decide.

The search agent has one tool, {% raw %}web_search, built on the Tavily API. The model decides what to search and how often, and returns the five best sources. The reader agent has scrape_url, which fetches a page with requests and pulls out clean text with BeautifulSoup. It picks the two most useful pages to read, and skips sites that can't be scraped.

Both steps feed text into a model with token limits, so the tools cut it down first. Each search snippet is capped at 300 characters, the text of each scraped page at 1,500, and the whole search output passed to the reader at 2,500. The comment next to the page limit in tools.py says why: so the LLM doesn't exceed token limits.

The writer is a chain that turns the research notes into a Markdown report with an introduction, key findings, analysis, a conclusion and sources.

The critic uses the same model as the writer, with a smaller output limit. Instead of asking it for a free-text review, I give it a Pydantic schema through with_structured_output:

class Critique(BaseModel):
    """Review of a research report."""
    score: int = Field(description="Overall quality score from 1 (poor) to 10 (excellent)")
    strengths: List[str] = Field(description="What the report does well (at most 4 items)")
    improvements: List[str] = Field(description="Specific suggestions to improve the report (at most 4 items)")
    verdict: str = Field(description="One-line overall verdict")

Because the score comes back as an integer field, the pipeline can compare it with a number directly instead of searching the critic's text for one. The improvements list is what the writer gets if a rewrite is needed.

The threshold is one constant in pipeline.py: MIN_GOOD_SCORE = 7. If the critic scores a report below 7, the writer rewrites it once using the critic's feedback, and the critic reviews the new version.

There is one case where the loop deliberately does nothing. If the review itself fails, the critique comes back with a score of 0, the improvement "Automatic review failed. Please review the report manually." and the verdict "Review unavailable". A score of 0 means the review failed, not that the report is bad, so the pipeline doesn't rewrite in that case.

The app shows the result as three numbers: the critic score, whether the report was rewritten, and a verdict of Good for 7 or more, otherwise Needs work. In the sample run on "Claude Fable 5.2", the critic scored the report 8/10, so no rewrite was needed. The sample report is in the repo.

The models are Groq's openai/gpt-oss-20b and openai/gpt-oss-120b. On Groq each of them has its own daily token limit, so the model names are set in one place in agents.py and can be switched if one model's quota runs out.

The free tier also limits tokens per minute. The pipeline handles the two kinds of limit differently:

The README lists what I want to add: entering your own API key in the interface, exporting the report as a PDF, running search and reading for several sub-questions in parallel, scoring sources for credibility, and telling apart people with the same name when the topic is a person.

The app is live on Streamlit Community Cloud, the code is on GitHub, and the case study has the full flow.

First published on sangamgupta.in.

── more in #ai-agents 4 stories · sorted by recency
── more on @langchain 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/when-to-use-an-agent…] indexed:0 read:4min 2026-11-30 · —