Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

Learning path · 6 steps

Agents with LangChain and LangGraph
  1. 1
    What LangChain Is For, and When to Skip It: Five Standard Parts, One Pipe, and a Decision Table
  2. 2
    Why Chains Break: No Branch, No Retry, No Pause, and the Same Refund Assistant as a LangGraph Graph
  3. 3
    LangGraph Nodes, Edges and State: Build Your First Graph, Route With a Conditional Edge, and Read the Run Three Ways
  4. 4
    Human-in-the-Loop and Checkpointing in LangGraph: interrupt, a SQLite Save Slot and Command(resume=...)
  5. 5
    Multi-Agent Patterns: Hub and Spoke in LangGraph, With Short Briefs, Owned Tools and a Retry the Hub Decides
  6. 6
    A Research Agent in LangGraph: Plan, Search, Read, Write, and a Check Node That Rejects Citations Nobody Read
  1. Blog
  2. /
  3. AI Engineering
  4. /
  5. Agents and MCP

Learning path: Agents with LangChain and LangGraph · Step 5 of 6

Multi-Agent Patterns: Hub and Spoke in LangGraph, With Short Briefs, Owned Tools and a Retry the Hub Decides

One agent with six tools and one long prompt picks the wrong tool more often. Split it like a hospital reception: a hub routes each message, and billing, tech and account spokes each get a four-field brief and two tools. Two spokes run side by side, the tech spoke's timeout is retried once, and a twice-failed identity check becomes "A person will follow up".

Chaand Sheikh

·27 November 2026Agents and MCP

What you will learn

  • Explain why one agent with every tool breaks down as the job grows
  • Build a hub that routes a message to focused spokes with LangGraph Send
  • Give each spoke a short brief and only its own tools
  • Let the hub retry a failed spoke once or hand the case to a person

Before you start

  • LangGraph Nodes, Edges and State
  • Claude Tool Use: How tool_use and tool_result Work

When an agent has too many jobs, it starts making mistakes, just like a person doing twenty jobs at once. One fix is to split the work: a hub that routes each request, and focused spokes that each do one job. This is the hub-and-spoke pattern, and in this article we build it in LangGraph on a support assistant. It runs with scripted test models, so no key is needed.

The use case: a support assistant

Customers write in with three kinds of questions, and each needs its own tools and rules:

KindExampleTools it needs
BillingWhy was I charged twice?Find the invoice, issue a refund
TechThe app crashes at login.Read the error log, check the status page
AccountChange my email.Verify identity, update the email

The first try: one big agent

The first idea most people try: one agent, give it everything. In our project that's all six tools in one agent; in a bigger app it's often twenty or more. The prompt grows too, with billing rules, tech steps and account policies all mixed together. With so many tools, the model picks the wrong one more often, the long prompt gets confusing, and changing one rule can break another.

Think of a hospital reception

A hospital reception desk doesn't treat anyone. A patient walks in, the desk listens and sends them to the right specialist. The specialist does the work, the report goes back to the desk, and the desk tells the patient what happens next. One rule: specialists don't send patients to each other. Everything goes through the desk. The desk is the hub; each specialist is a spoke.

Hub and spoke X no spoke-to-spoke edge hub routes, retries billingfind_invoiceissue_refund techread_error_logstatus_page accountverify_identityupdate_email brief out (4 fields) report back
Each spoke owns two tools and gets a short brief. Every report goes back to the hub; spokes never call each other.

Each spoke owns its tools

"""Each spoke owns only its own tools. Data is a small in-memory sample."""

INVOICES = {"c-101": ("INV-7", 49.00), "c-102": ("INV-9", 19.00)}
CRASHES = {"c-102": "bug 512"}
VERIFIED = {"c-101", "c-102"}
FLAKY = {"status_page": 1}          # fails this many times, then works


class ToolError(Exception):
    pass


def status_page(brief):
    if FLAKY["status_page"] > 0:
        FLAKY["status_page"] -= 1
        raise ToolError("status page timed out")
    return "fix out in 2.4.1"


def verify_identity(brief):
    if brief["customer"] not in VERIFIED:
        raise ToolError("identity check failed")
    return "identity ok"

# ... find_invoice, issue_refund, read_error_log, update_email ...

SPOKE_TOOLS = {
    "billing": [find_invoice, issue_refund],
    "tech": [read_error_log, status_page],
    "account": [verify_identity, update_email],
}
ALL_TOOLS = [t for tools in SPOKE_TOOLS.values() for t in tools]

This is an excerpt: the other four tools are one-line lookups in the same sample data. SPOKE_TOOLS is one dictionary. ALL_TOOLS collects six tools, but each spoke only ever sees two. Two lines set up trouble on purpose: FLAKY makes the status page time out once, and verify_identity fails for a customer we don't know.

The state and the brief

class HubState(TypedDict, total=False):
    message: str
    customer: str
    picked: list
    reports: Annotated[list, operator.add]
    reply: str


class Brief(TypedDict):
    spoke: str
    customer: str
    question: str
    attempt: int

HubState is the notebook: the message, the customer, the spokes the hub picked, the reports, and the final reply. reports is annotated with operator.add, so when two spokes send a report, both are added and nothing gets replaced. Brief is what a spoke receives: just four fields. A spoke never sees the whole notebook or the chat history. It gets a short brief, and that keeps it focused.

The hub routes

    def hub(state: HubState) -> dict:
        prompt = ("Which spokes: billing, tech, account? Comma list.\n"
                  + state["message"])
        words = hub_model.invoke(prompt).content.split(",")
        picked = [w.strip() for w in words if w.strip() in SPOKE_TOOLS]
        return {"picked": picked or ["account"]}

    def send_out(state: HubState) -> list:
        return [Send("spoke", Brief(spoke=name, customer=state["customer"],
                                    question=state["message"], attempt=1))
                for name in state["picked"]]

The hub asks its model which spokes to use. For "Refund the double charge, and the app crashes at login", the model says billing, tech. We split on the comma and keep only names that are in SPOKE_TOOLS, so a strange word from the model is simply dropped; if nothing is left, the account spoke takes it. send_out turns each name into a Send with its own brief. Two names, two briefs, and both spokes start at the same time.

A spoke does one job

    def spoke(brief: Brief) -> dict:
        name = brief["spoke"]
        try:
            facts = [tool(brief) for tool in SPOKE_TOOLS[name]]
        except ToolError as err:
            return {"reports": [{"spoke": name, "ok": False,
                                 "error": str(err), "attempt": brief["attempt"]}]}
        prompt = f"You are the {name} spoke. Report in one line: {facts}"
        text = spoke_models[name].invoke(prompt).content
        return {"reports": [{"spoke": name, "ok": True,
                             "text": text, "attempt": brief["attempt"]}]}

The spoke runs its own tools one by one and collects the answers as facts. If a tool raises ToolError, the spoke doesn't try to fix anything; it reports ok: False with the error and the attempt number. Otherwise the spoke's own model, with its own short prompt, writes one line.

The hub decides on failure

    def retry_or_answer(state: HubState):
        failed = [r for r in latest(state["reports"]).values()
                  if not r["ok"] and r["attempt"] < MAX_TRIES]
        if not failed:
            return "answer"
        return [Send("spoke", Brief(spoke=r["spoke"], customer=state["customer"],
                                    question=state["message"], attempt=r["attempt"] + 1))
                for r in failed]

    def answer(state: HubState) -> dict:
        done, notes = [], []
        for r in latest(state["reports"]).values():
            if r["ok"]:
                done.append(r["text"])
            else:
                notes.append(f"{r['spoke']}: {r['error']}")
        prompt = f"Write one reply from: {done}"
        reply = hub_model.invoke(prompt).content
        if notes:
            reply += " A person will follow up. Notes: " + "; ".join(notes)
        return {"reply": reply}

The hub decides, because the hub sees the whole picture. retry_or_answer looks at the latest report from each spoke. If one failed and its attempt is below MAX_TRIES (2), the same spoke gets a new brief with attempt 2. If nothing is left to retry, we go to answer, which joins the good reports into one reply, and adds "A person will follow up" with what went wrong if a spoke still failed. Retry once, or hand it to a person; one failing spoke doesn't break the whole answer.

The wiring: no spoke to spoke

    builder = StateGraph(HubState)
    builder.add_node("hub", hub)
    builder.add_node("spoke", spoke)
    builder.add_node("check", check)
    builder.add_node("answer", answer)
    builder.add_edge(START, "hub")
    builder.add_conditional_edges("hub", send_out, ["spoke"])
    builder.add_edge("spoke", "check")
    builder.add_conditional_edges("check", retry_or_answer, ["spoke", "answer"])
    builder.add_edge("answer", END)
    return builder.compile()

From START to the hub; send_out decides which spokes run; every spoke goes to check; retry_or_answer picks the road back to a spoke or on to answer; then END. Look for an edge from one spoke to another: there isn't one. That's the rule, written in code.

One message through the hub

Customer: Refund the double charge, and the app crashes at login.
  hub: {'picked': ['billing', 'tech']}
  spoke: {'reports': [{'spoke': 'billing', 'ok': True, 'text': 'Invoice INV-9 was paid twice. Refunded 19.00.', 'attempt': 1}]}
  spoke: {'reports': [{'spoke': 'tech', 'ok': False, 'error': 'status page timed out', 'attempt': 1}]}
  check: None
  spoke: {'reports': [{'spoke': 'tech', 'ok': True, 'text': 'Crash is bug 512. Fixed in version 2.4.1.', 'attempt': 2}]}
  check: None
  answer: {'reply': 'Refund sent, and the login fix is out.'}
  model calls: {'hub': 2, 'billing': 1, 'tech': 1}

The hub picks billing and tech (hub call 1). Two briefs go out at the same time. Billing finds INV-9 and refunds 19.00. The tech spoke hits the status-page timeout, so its report says ok: False, attempt 1. The hub sends a second brief, and this time it works: bug 512, fixed in 2.4.1. Answer joins both reports (hub call 2).

Three messages, three paths

MessagePathModel calls
Why was I charged twice?hub, billing, answer{'hub': 2, 'billing': 1}
Refund the double charge, and the app crashes at login.hub, billing + tech, tech retried once, answer{'hub': 2, 'billing': 1, 'tech': 1}
Change my email (unknown customer)hub, account fails twice, answer with a handover note{'hub': 2, 'account': 0}

For the email change, the identity check failed, then failed again on attempt 2, so the account spoke never called its model at all. The reply ends: A person will follow up. Notes: account: identity check failed. Same code, and the hub picked a different path each time.

One agent or hub and spoke?

One agentHub and spoke
LatencyNo routing step, quick for easy requestsOne more hop, but spokes can work side by side
CostA long prompt on every callMore calls, each with a small prompt
ClarityOne tangled promptEach agent has one clear job
TestingEverything at onceEach spoke on its own (the project's 4 tests pass)

A small app with a few tools is fine with one agent. With many tools and many jobs, use a hub. The exact latency and cost numbers depend on your provider, and they change.

Common mistakes

  • Handing spokes the whole chat. A four-field brief keeps a spoke focused and its prompt small.
  • Letting spokes call each other. Paths become impossible to follow; route everything through the hub.
  • Retrying inside the spoke. The spoke reports the error; the hub, which sees every report, decides.
  • Trusting the router's words. Filter the hub's answer against the known spokes, with a fallback.
  • No handover. After the last try, say a person will follow up and include what failed.

Quick recap

  • The hub routes each request to the right spokes.
  • Each spoke gets a short brief, not the whole chat, and owns only its own tools.
  • Spokes never talk to each other; everything goes through the hub.
  • When a spoke fails, the hub decides: retry once, or hand it to a person.

Try it yourself

Set FLAKY = {"status_page": 2} in tools.py and run the second message again: does tech still recover with MAX_TRIES = 2, and what does the reply say? To see a single agent that loops until a check passes, read A Research Agent in LangGraph.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in the learning path Agents with LangChain and LangGraph · step 5 of 6

Previous
Human-in-the-Loop and Checkpointing in LangGraph: interrupt, a SQLite Save Slot and Command(resume=...)
Next post
A Research Agent in LangGraph: Plan, Search, Read, Write, and a Check Node That Rejects Citations Nobody Read

Related course on Udemy

Become an AI Engineer: LLMs, RAG, Agents and MCP

Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)

Related posts

Context Engineering for a Long-Running Agent: Clear, Compact, Take Notes, Prove It

A support agent forgets the customer's name, order and contact choice after twenty turns and fails 0 of 4 checks. Measure the window, clear old tool output, compact old turns and keep a notes file, and the same chat passes 4 of 4 with 470 tokens instead of 2,945.

What LangChain Is For, and When to Skip It: Five Standard Parts, One Pipe, and a Decision Table

LangChain is a box of standard parts (models, prompts, retrievers, tools, parsers) that snap together with a pipe. The same refund question through the plain Anthropic SDK (1 import, 13 lines) and a chain (3 imports, 14 lines) gives the same answer word for word. It pays off when the bot grows; for one call, the SDK is simpler, with 16 packages instead of 38.

Why Chains Break: No Branch, No Retry, No Pause, and the Same Refund Assistant as a LangGraph Graph

A refund assistant built three ways. The chain runs classify, retrieve, reply once: it answers an opening-hours question with the billing line, misses the 30-day window, and sends a $150 refund with approved False. Plain if/while fixes it but hides the flow; a LangGraph StateGraph puts the branch, the retry loop and the approval stop in the arrows.

LangGraph Nodes, Edges and State: Build Your First Graph, Route With a Conditional Edge, and Read the Run Three Ways

Two small graphs. A refund skeleton: SupportState, a classify node, a route function on a conditional edge, and an Annotated log that appends instead of overwriting. A help desk: classify and answer call a scripted test model, spam goes straight to END after one model call instead of two, and the same run read with invoke, stream values and stream updates.

On this page

  • The use case: a support assistant
  • The first try: one big agent
  • Think of a hospital reception
  • Each spoke owns its tools
  • The state and the brief
  • The hub routes
  • A spoke does one job
  • The hub decides on failure
  • The wiring: no spoke to spoke
  • One message through the hub
  • Three messages, three paths
  • One agent or hub and spoke?
  • Common mistakes
  • Quick recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Become an AI Engineer: LLMs, RAG, Agents and MCP

Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.