{"slug": "day-16-30-supervisor-pattern", "title": "Day 16/30: Supervisor Pattern", "summary": "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.", "body_md": "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.\n\nAfter 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.\n\nThat'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.\n\nHere's an example of how I implemented the Supervisor pattern using LangGraph and MCP:\n\n``` python\nimport langgraph as lg\nfrom mcp import tools\n\n# Define the supervisor agent\nsupervisor = lg.StateGraph()\nsupervisor.add_node(\"start\", tools.prompt(\"What is your question?\"))\nsupervisor.add_node(\"orders\", tools.prompt(\"What is your order number?\"))\nsupervisor.add_node(\"shipments\", tools.prompt(\"What is your shipment tracking number?\"))\nsupervisor.add_node(\"returns\", tools.prompt(\"What is your return reason?\"))\n\n# Define the worker agents\norders_agent = lg.StateGraph()\norders_agent.add_node(\"start\", tools.prompt(\"Order details:\"))\norders_agent.add_node(\"response\", tools.response(\"Your order will be shipped soon.\"))\n\nshipments_agent = lg.StateGraph()\nshipments_agent.add_node(\"start\", tools.prompt(\"Shipment details:\"))\nshipments_agent.add_node(\"response\", tools.response(\"Your shipment is on its way.\"))\n\nreturns_agent = lg.StateGraph()\nreturns_agent.add_node(\"start\", tools.prompt(\"Return details:\"))\nreturns_agent.add_node(\"response\", tools.response(\"Your return has been processed.\"))\n\n# Define the conditional edges between the supervisor and worker agents\nsupervisor.add_conditional_edges(\n    \"start\",\n    {\n        \"orders\": lambda x: x.contains(\"order\"),\n        \"shipments\": lambda x: x.contains(\"shipment\"),\n        \"returns\": lambda x: x.contains(\"return\")\n    }\n)\n\n# Define the conditional edges between the worker agents and the supervisor\norders_agent.add_conditional_edges(\n    \"start\",\n    {\n        \"response\": lambda x: True\n    }\n)\n\nshipments_agent.add_conditional_edges(\n    \"start\",\n    {\n        \"response\": lambda x: True\n    }\n)\n\nreturns_agent.add_conditional_edges(\n    \"start\",\n    {\n        \"response\": lambda x: True\n    }\n)\n\n# Run the supervisor agent\nsupervisor.run()\n```\n\nThis 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.\n\nOne 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.\n\nAs 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.", "url": "https://wpnews.pro/news/day-16-30-supervisor-pattern", "canonical_source": "https://dev.to/yashwanth_kasi/day-1630-supervisor-pattern-3ghc", "published_at": "2026-07-26 05:51:16+00:00", "updated_at": "2026-07-26 06:29:09.350047+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "large-language-models"], "entities": ["LangGraph", "MCP"], "alternates": {"html": "https://wpnews.pro/news/day-16-30-supervisor-pattern", "markdown": "https://wpnews.pro/news/day-16-30-supervisor-pattern.md", "text": "https://wpnews.pro/news/day-16-30-supervisor-pattern.txt", "jsonld": "https://wpnews.pro/news/day-16-30-supervisor-pattern.jsonld"}}