Level 2 · Agents & Sub-Agents

Routing Tasks to Specialized Sub-Agents

Learn how to optimize your coding agent by using fast decision models to delegate tasks to specialized sub-agents, reducing latency and cost while improving accuracy.

Moving from Chatbots to Autonomous Agents

When you transition from a standard chat AI to a coding agent like Claude Code, you are moving from a conversation to a control loop. A standard AI simply replies to your text. An agent possesses tools, which are programmatic capabilities that allow it to read your file system, edit code, and run terminal commands. Because the agent can act on your behalf, it needs to manage context, which is the total pool of information (code, history, and files) the model can see at any given moment.

The challenge for beginners is the temptation to let one large, expensive model handle every single task. While a large model is smart, it is slow and costly when performing simple chores like searching for a file or checking a background process. If your agent is constantly re-reading your entire codebase for every small request, you will quickly hit context limits and see your bills spike. Professional agent workflows solve this by moving away from a single-model approach toward a system of routing.

The Power of Fast Decision Models

To improve efficiency, we introduce decision models. These are specialized AI engines designed for speed and structured output rather than conversation. Think of them as intelligent logic gates. While a large language model is like a deep-thinking professor, a decision model is like a high-speed switchboard operator. It uses what researchers call System 1 thinking: fast, intuitive, and immediate. These models are optimized to provide binary choices or classifications in milliseconds, often reaching speeds 200 times faster than traditional LLMs.

By placing a decision model at the front of your workflow, you create a model router. When you give a command, the decision model analyzes it and determines its complexity. If the task is a simple status check, it handles it instantly or routes it to a tiny, cheap model. If the task requires deep architectural changes, only then does it pass the request to the expensive, high-reasoning model. This prevents the large model from being bogged down by trivialities, keeping your primary agent sharp and focused on logic.

Building Specialized Sub-Agents with MCP

Once you have a router, you can begin delegating work to specialized sub-agents. A sub-agent is a version of the AI configured for a very narrow task, such as security auditing, database migrations, or writing unit tests. Instead of one agent that is mediocre at everything, you deploy dozens of agents that are experts in their specific domains. These agents gain their expertise through specific instructions and the Model Context Protocol (MCP).

MCP is a standard that allows your agents to connect to external tools like GitHub, cloud providers, or local databases without custom configuration for each tool. For example, a sub-agent dedicated to deployment might have an MCP connection to your cloud host, while a security sub-agent has a toolset for scanning vulnerabilities. This specialization ensures that the agent only sees the context it needs for the job at hand, reducing the risk of hallucinations and errors that occur when a model is overloaded with irrelevant information.

Managing Lifecycle and Context Handoffs

Maintaining a healthy agent environment requires active monitoring of your sessions. As an agent works, it accumulates tokens in its context window. Once that window reaches about 85 percent capacity, the agent's performance typically degrades. You can implement an auto-handoff mod that detects this threshold and automatically migrates the essential task data to a fresh session. This keeps the reasoning clear and prevents the agent from forgetting earlier instructions.

To keep track of these complex background processes, you should use visualization tools like flight recorders or output trays. These tools show you exactly which models are being triggered, which MCP tools are active, and how much each step costs. By treating your agent as a team of specialists rather than a single entity, you create a robust system that can handle complex software engineering tasks with the reliability and speed required for professional development.

Key takeaways

  • Use high-speed decision models as logic gates to route simple tasks away from expensive reasoning models.
  • Divide complex projects into sub-tasks handled by specialized agents with narrow, expert instructions.
  • Leverage the Model Context Protocol (MCP) to give your sub-agents secure access to external tools and databases.
  • Monitor context usage and trigger automatic session handoffs when usage hits 85 percent to maintain accuracy.
  • Implement flight recorders to visualize agent steps and track token costs across different models.