I'm Frank Bonalde, an AI engineer based in São Paulo. In my previous post I built a root cause analysis agent with RAG. This time I went multi-agent: several agents researching the same topic in parallel, and a UI where you can watch them work live.

The problem

A single agent that searches, fetches images and writes an explanation does it all one step after another. It's slow, and while it works you stare at a spinner with no idea what it's doing.

I wanted something different: ask "what is the planet Mercury like?" and see three specialists split the work, each one with its own live log, then merge everything into one answer.

MCPMultiAgentsResearch UI: answer card with images and key points on the left, live activity panel for the Researcher, Multimedia and Learning agents on the right

The stack

  • LangGraph for orchestration and state, LangChain for the agents
  • MCP server (servidor_wiki.py) exposing Wikipedia tools over stdio, loaded with langchain-mcp-adapters
  • Groq LLMs behind a fallback cascade (with_fallbacks)
  • Chroma + intfloat/multilingual-e5-base embeddings (local, via sentence-transformers)
  • Reflex for the frontend, fed by LangGraph's astream_events

Fan-out, not a relay

My first idea was a relay: one agent passes its result to the next. That makes the slowest chain possible. Instead, a supervisor extracts the topic once and fans it out to three agents that run in parallel:

user → validation → supervisor ─┬─> Researcher (search_articles, get_summary) ├─> Multimedia (get_images) └─> Learning (Chroma cache → teacher) ↓ final answer 

The validation node runs first: it sanitizes the input and checks for prompt injection with regex patterns. No LLM there, so it's cheap and deterministic.

The Learning agent works in two phases. Phase 1 starts with the others and checks Chroma: "have I already learned this?" If not, Phase 2 waits for the Researcher's result, rewrites it as a teacher would (key points plus a detailed explanation) and stores it in Chroma for next time.

Here's the wiring, simplified:

from langgraph.graph import StateGraph, START, END # Graph: validation -> supervisor -> 3 parallel branches -> final answer builder = StateGraph(AgentState) builder.add_node("validation", validation_node) builder.add_node("supervisor", supervisor_node) builder.add_node("researcher", researcher_node) builder.add_node("multimedia", multimedia_node) builder.add_node("learning_cache", learning_phase1_node) # checks Chroma builder.add_node("learning_teach", learning_phase2_node) # explains + stores builder.add_node("final_answer", final_answer_node) builder.add_edge(START, "validation") builder.add_edge("validation", "supervisor") # Fan-out: one edge per branch, so they run in the same step (in parallel) for branch in ("researcher", "multimedia", "learning_cache"): builder.add_edge("supervisor", branch) # Phase 2 of Learning depends on what the Researcher found builder.add_edge("researcher", "learning_teach") # Fan-in: the final node waits for every branch to finish builder.add_edge(["multimedia", "learning_cache", "learning_teach"], "final_answer") builder.add_edge("final_answer", END) graph = builder.compile() 

Each agent only knows its own tools

Every agent is built with bind_tools() scoped to its own tools. The Researcher can't see the image tool, the Multimedia agent can't search articles, and the Learning agent has no MCP tools at all. Nobody can run code, open a shell or touch the filesystem. Limiting capabilities by design turned out to be much cheaper than sandboxing.

Two more guards: a network allowlist installed at startup (only the Groq API and Hugging Face for the initial model download), and a shared rate limiter. Fan-out means three agents hitting Groq at the same moment, so one counter per agent would hide the real burst.

One MCP gotcha worth knowing: load_mcp_tools doesn't give you the plain string your server returns. It wraps it as [{'type': 'text', 'text': '...'}], so I centralized a small extract_text_result() helper instead of parsing it in every agent.

The first thing that broke: Mercury became Jupiter

I asked about Mercury after having asked about Jupiter. The answer came back fast. Too fast. It was the cached Jupiter explanation.

The Learning agent's Phase 1 accepted any cached document with a similarity above 0.75. For an embedding model, "Mercury" and "Jupiter" are close neighbors: both are planets, same solar system, same vocabulary. The cache did exactly what I told it to do. It found something similar. I needed something identical.

There was a second cause hiding upstream: the supervisor was trimming "planet Mercury" down to just "Mercury", throwing away the word that tells a planet apart from the element or the god.

The fix

Three layers, because no single one was enough:

  1. Raise the threshold from 0.75 to 0.90.
  2. Require a meaningful word overlap between the requested topic and the cached title.
  3. Tell the supervisor to keep disambiguating qualifiers ("planet Mercury" stays "planet Mercury").
SIMILARITY_THRESHOLD = 0.90 # was 0.75: different planets scored above it def is_real_cache_hit(topic: str, cached_title: str, score: float) -> bool: """Accept a cached answer only if it's semantically close AND shares words with the topic.""" # Layer 1: stricter semantic similarity if score < SIMILARITY_THRESHOLD: return False # Layer 2: lexical check, ignoring short words like "the" or "of" topic_words = {w for w in topic.lower().split() if len(w) > 3} title_words = set(cached_title.lower().split()) # No meaningful shared word -> it's a neighbor topic, not the same one return bool(topic_words & title_words) 

Other things that broke along the way

  • State reducer: I used add_messages to accumulate the research steps, but it coerces every item into a chat message and crashed on my plain dicts. Switching to operator.add (simple list concatenation) fixed it.
  • Duplicate events: astream_events also emits LangChain's internal sub-events, so every step showed up twice in the live panel. Filtering by node name solved it.
  • Structured output failing across the whole fallback chain: when every model in the cascade returned malformed JSON, the answer was empty. Now it falls back to the Researcher's plain summary. MCPMultiAgentsResearch UI with live agent activity panel
  • A slow MCP server: the first call was the slowest. A warmup at startup made searches noticeably faster.

Lessons

  • In a semantic cache, a hit isn't proof. Similarity measures how close two topics are, not whether they're the same one.
  • Fan-out multiplies everything: speed, but also rate-limit pressure and failure modes.
  • Scope tools per agent. It's the cheapest security you'll ever add.
  • Make agents visible. The live activity panel started as a UX idea and ended up being my best debugging tool.

What's next

  • A retry edge for MCP connection failures (max 2 retries)
  • Per-node timing in the activity panel, to find exactly where the latency is

The code is on GitHub: MCPMultiAgentsResearch. If you're building multi-agent systems or working with MCP, I'd love to compare notes in the comments.