cd /news/ai-agents/day-16-30-supervisor-pattern · home topics ai-agents article
[ARTICLE · art-74022] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Day 16/30: Supervisor Pattern

A developer implemented the Supervisor pattern using LangGraph and MCP to fix a support bot that was failing in production due to context confusion. The pattern uses a manager agent to delegate tasks to specialized worker agents for orders, shipments, and returns, improving accuracy and reducing errors.

read3 min views1 publishedJul 26, 2026

I recently spent hours debugging a support bot that was supposed to handle customer inquiries about orders, shipments, and returns. The bot was built using LangGraph and MCP, and it worked great in isolation, but when we deployed it to production, it started to fail in unexpected ways. Sometimes it would answer questions about orders when the customer was asking about returns, or vice versa. It was as if the bot had forgotten what context it was in, and was just making random guesses.

After digging through the code, I realized that the problem was that the bot was trying to do too much itself. It was a single agent that was responsible for understanding the customer's question, retrieving the relevant information from the database, and generating a response. This was causing the bot to get overwhelmed and lose track of what it was doing.

That's when I decided to try out the Supervisor pattern. The idea is to create a manager agent that delegates tasks to specialized worker agents. In this case, I created a supervisor agent that would receive the customer's question and then delegate it to one of three worker agents: an orders agent, a shipments agent, or a returns agent. Each worker agent was responsible for a specific task, such as retrieving information from the database or generating a response.

Here's an example of how I implemented the Supervisor pattern using LangGraph and MCP:

import langgraph as lg
from mcp import tools

supervisor = lg.StateGraph()
supervisor.add_node("start", tools.prompt("What is your question?"))
supervisor.add_node("orders", tools.prompt("What is your order number?"))
supervisor.add_node("shipments", tools.prompt("What is your shipment tracking number?"))
supervisor.add_node("returns", tools.prompt("What is your return reason?"))

orders_agent = lg.StateGraph()
orders_agent.add_node("start", tools.prompt("Order details:"))
orders_agent.add_node("response", tools.response("Your order will be shipped soon."))

shipments_agent = lg.StateGraph()
shipments_agent.add_node("start", tools.prompt("Shipment details:"))
shipments_agent.add_node("response", tools.response("Your shipment is on its way."))

returns_agent = lg.StateGraph()
returns_agent.add_node("start", tools.prompt("Return details:"))
returns_agent.add_node("response", tools.response("Your return has been processed."))

supervisor.add_conditional_edges(
    "start",
    {
        "orders": lambda x: x.contains("order"),
        "shipments": lambda x: x.contains("shipment"),
        "returns": lambda x: x.contains("return")
    }
)

orders_agent.add_conditional_edges(
    "start",
    {
        "response": lambda x: True
    }
)

shipments_agent.add_conditional_edges(
    "start",
    {
        "response": lambda x: True
    }
)

returns_agent.add_conditional_edges(
    "start",
    {
        "response": lambda x: True
    }
)

supervisor.run()

This code defines a supervisor agent that delegates tasks to three worker agents based on the customer's question. Each worker agent is responsible for a specific task, such as retrieving information from the database or generating a response.

One practical gotcha to watch out for when using the Supervisor pattern is that it can be easy to create a situation where the supervisor agent is delegating tasks to worker agents that are not equipped to handle them. For example, if the orders agent is not designed to handle questions about shipments, it may not be able to generate a correct response. To avoid this, it's essential to carefully define the conditional edges between the supervisor and worker agents, and to ensure that each worker agent is designed to handle the tasks that are delegated to it.

As we continue to build more complex agentic AI systems, we'll need to develop new patterns and techniques for managing the interactions between agents. Tomorrow, we'll explore another key concept that will help us build more robust and scalable AI systems.

── more in #ai-agents 4 stories · sorted by recency
── more on @langgraph 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/day-16-30-supervisor…] indexed:0 read:3min 2026-07-26 ·