9 Assembling MAS with Subagents
This chapter covers
- What subagents are and why you’d use them for task execution?
- Implementing the infrastructure enabling subagents in our framework
- Common MAS patterns that can be used with subagents
And now the moment you’ve been waiting for: combining multiple LLM agents into a MAS that works faster and more efficiently than any single agent. To do this, we enable the use of subagents in our framework.
In a MAS, an LLM agent uses subagents during task execution. To avoid confusion, we’ll call this LLM agent the main LLM agent. Remember, subagents are constructed in the same way as the main LLM agent. In other words, the main LLM agent and its subagents are all objects from the same class. In our framework, that class is LLMAgent. This means we can build subagents with the same LLMAgentBuilder we’ve been using all along.
To enable an LLM agent to dispatch a subagent, harnesses like Claude Code and OpenCode typically use a tool that operates over a registry of subagents. When an LLM agent decides to use this tool, it reasons over the descriptions of available subagents and selects the one best suited for the job. Executing the tool call means constructing the subagent and having it perform the delegated task. When the subagent completes the task, the result is packaged into the tool call’s result and returned to the LLM agent like any other tool call execution.