Sub-Agents for AI Operations: When to Split Work and How to Check the Results
Back to Blog
AI Agents· 8 min read

Sub-Agents for AI Operations: When to Split Work and How to Check the Results

A sub-agent is a separate worker with its own context that returns a short result to a lead agent. This guide covers when splitting work helps, when it only adds cost, and a tested orchestrator that checks every worker's output.

ML
By Mneme Labs
NEPA AI · Building autonomous systems for creators and businesses
#ai-agents#sub-agents#orchestration#multi-agent

A sub-agent is a worker that a lead agent starts for one piece of a job. The worker has its own instructions, its own tool access and its own context window. It does the task and sends back a result, usually a short summary or structured data. The lead agent never sees the worker's full working notes.

Two reasons to do this are common. One is context: a side task such as searching a long log can fill the main conversation with text you will not reread. The other is parallel work: twenty independent items can be handled by several workers at once. Both reasons come with costs, and this guide spends as much time on those costs as on the benefits. It builds a small orchestrator in Python that splits a job, runs workers, and refuses to merge results that fail a check. The data is invented, and the worker is a keyword stand-in for a model call, so the example tests the coordination code and says nothing about model quality.

What the vendors say a sub-agent is for

Claude Code's documentation describes a subagent as an assistant that runs in its own context window with a custom system prompt, specific tool access and independent permissions. It suggests using one when a side task would flood the main conversation with search results, logs or file contents, and notes that each subagent sends its own requests, which count toward the same usage limits as the main conversation. It also lists restricting which tools a subagent can use, and routing work to a cheaper model, as reasons to define them.

OpenAI's Agents SDK documentation separates two patterns. In "agents as tools," a manager agent keeps control of the conversation and calls specialists for bounded subtasks. In a handoff, a specialist takes over the conversation for the rest of the turn. A sub-agent in this guide is the first pattern: the lead keeps the job and the worker returns a result.

Anthropic's engineering team describes its research feature as an orchestrator-worker design, where a lead agent plans, starts subagents that search in parallel, and compiles what they return. Its general guidance on building agents draws a line between parallelization, where subtasks are fixed in advance, and orchestrator-workers, where the lead decides the subtasks from the input. If your subtasks are known ahead of time, plain code with parallel calls is simpler than an agent that decides how to split.

The cost side

Anthropic's post on its research system gives numbers worth knowing. In its data, agents used about four times the tokens of a chat, and multi-agent systems about fifteen times. It concludes that these systems pay off for tasks valuable enough to cover the cost, and that fields where every agent needs the same context, or where steps depend heavily on each other, are a poor fit today. It said most coding tasks have fewer truly parallel pieces than research does. Those figures come from Anthropic's own product and measurements, so treat them as a warning about order of magnitude and not as a forecast for your setup.

The same post reports that early versions made coordination mistakes: starting dozens of subagents for a simple query, duplicating each other's searches, and leaving gaps when instructions were short and vague. Its fixes were explicit effort rules in the prompt and detailed task descriptions for each worker.

Decision grid of four questions about independence, context flooding, shared context and task value, each pointing toward a sub-agent or toward one agent
Four questions to ask before splitting work. The cost note refers to Anthropic's reported figure for its own research system. Conceptual diagram by Mneme Labs.

A decision rule

Use the grid above as a checklist. A sub-agent is a good fit when the pieces are independent, when the raw material is large and you only need a conclusion, when each piece needs only its own slice of information, and when the task is valuable enough to justify extra model calls. If steps depend on each other, or every part needs the full picture, keep the work in one agent and use a plain sequence of steps.

Before splitting, also try the cheaper options. A skill gives one agent a written procedure, as covered in the guide on agent skills. Saved notes give it facts from earlier work, covered in the memory guide. Both are cheaper than a second model call, and neither adds a coordination problem.

A worked example: sorting support tickets

Take a fictional shop with twelve support tickets to label as billing, bug or other. The lead splits the tickets into three shards and starts one worker per shard. Each worker sees only its shard. The lead checks each result before merging.

The code below is the whole orchestrator. The worker argument is any function that takes a list of tickets and returns labels. In a real system it would call a model with a brief for the shard.

from concurrent.futures import ThreadPoolExecutor, as_completed, TimeoutError as FutureTimeout

ALLOWED = {"billing", "bug", "other"}
MAX_WORKERS = 4          # upper bound, whatever the caller asks for


def split(items, n):
    """Round-robin shards. Each worker sees only its own shard."""
    return [items[i::n] for i in range(n) if items[i::n]]


def validate(result, shard_ids):
    """A worker must return {"labels": {id: label}} covering exactly its shard."""
    if not isinstance(result, dict) or not isinstance(result.get("labels"), dict):
        return "bad shape"
    got, want = set(result["labels"]), set(shard_ids)
    if got != want:
        return "ids mismatch: missing %s, extra %s" % (sorted(want - got), sorted(got - want))
    if any(v not in ALLOWED for v in result["labels"].values()):
        return "label not allowed"
    return None


def orchestrate(tickets, worker, workers=3, timeout=5.0):
    if not tickets:                                      # nothing to do is a complete, empty result
        return {"labels": {}, "failed": [], "complete": True}
    workers = max(1, min(int(workers), MAX_WORKERS))     # at least one worker, never more than the cap
    shards = split(tickets, workers)
    merged, failed = {}, []
    pool = ThreadPoolExecutor(max_workers=len(shards))
    futures = {pool.submit(worker, shard): i for i, shard in enumerate(shards)}
    seen = set()
    try:
        for fut in as_completed(futures, timeout=timeout):
            i = futures[fut]
            seen.add(i)
            ids = [t["id"] for t in shards[i]]
            try:
                result = fut.result()
            except Exception as e:                       # one worker failing must not sink the rest
                failed.append({"shard": i, "ids": ids, "reason": "error: %s" % e})
                continue
            problem = validate(result, ids)
            if problem:
                failed.append({"shard": i, "ids": ids, "reason": problem})
            else:
                merged.update(result["labels"])
    except FutureTimeout:
        pass
    for i, shard in enumerate(shards):
        if i not in seen:
            failed.append({"shard": i, "ids": [t["id"] for t in shard], "reason": "timeout"})
    pool.shutdown(wait=False, cancel_futures=True)
    return {"labels": merged, "failed": failed,
            "complete": not failed and set(merged) == {t["id"] for t in tickets}}

Four design choices matter more than the threading. The worker count is forced into a range in code, from one up to a cap of four, so a lead that asks for fifty workers still gets four and a request for zero or fewer gets one. An empty batch returns a complete, empty result and never starts a worker. Each result is checked against what the lead expected: the right shape, exactly the ids in that shard, and only allowed labels. A failed or late shard is recorded with its ticket ids and a reason, and the rest of the results are kept. And the final answer carries a complete flag, which is true only if every ticket came back exactly once.

Annotated run on twelve synthetic tickets in three shards, where shard one fails and the merged result lists eight labels, complete false, and the four failed ticket ids
A synthetic run where one worker raises an error. The merged result says what is missing. Original Mneme Labs diagram, invented data.

What the tests covered

The tests used the stand-in keyword worker and a set of deliberately faulty ones. With a correct worker, all twelve tickets came back labeled and the result was marked complete. Asking for fifty workers produced four shards. Asking for zero or negative workers produced one worker holding all twelve tickets, and a number given as a string was converted while a non-numeric string was rejected. An empty ticket list returned a complete, empty result with the worker never called, for any worker count. A worker that raised an error on the shard holding one ticket left eight labels merged, listed that shard's four ids as failed, and marked the result incomplete. A worker that dropped one id from every shard was rejected on every shard with an "ids mismatch" reason, and nothing was merged. A worker that invented a label outside the allowed set was rejected. A worker that took longer than the timeout was reported as a timeout while the others were kept.

These checks show that the coordination code handles those failures. They do not show that real model workers label tickets well, or that three workers beat one on your data. Measure that on a sample you have checked by hand.

Writing the brief for each worker

Anthropic's post says each subagent needs an objective, an output format, guidance on tools and sources, and clear task boundaries. In the ticket example, a useful brief says to label each listed ticket with exactly one of three labels, to return only a JSON object keyed by ticket id, to use only the ticket text provided, and to return "other" when unsure rather than guess. A brief that says only "sort these tickets" invites variation that the check will reject.

Failure cases

Duplicate or missing work. Vague instructions make workers repeat each other or skip pieces. Splitting by explicit id, as the example does, makes both visible. With open-ended research, give each worker a distinct angle and a source list.

Too many workers. The lead may over-delegate on a simple job. Cap the count in code and put effort guidance in the prompt.

A summary that drops what matters. A worker returns a compressed result, and compression loses detail. If the lead must act on a number, a date or a quotation, require the worker to return it verbatim with its source.

Worker output as an attack path. If a worker reads web pages or customer text, its summary can carry injected instructions to the lead. Treat worker output as data, keep the lead's permissions small, and see the browser control guide for how to enforce an action allowlist.

Two workers writing to the same place. Give workers read-only tools where possible, and let the lead alone make changes after the check passes.

Timeouts that do not stop work. In the example, the timeout stops the lead from waiting. It does not stop a running thread. Real model clients need their own per-call timeouts, and writes should not be retried blindly, as the guide on retries and failures explains.

Cost surprises. Each worker is its own set of model calls. Set a worker cap and a budget before the first run, and read the first run's usage before scaling up.

Next step

Pick a job you already do with one agent that has independent pieces, such as a batch of documents or a list of pages to summarize. Write the worker brief and the validation function first, because the check defines what a good result is. Run it with one worker, then with three, on a sample you can verify by hand, and compare both the results and the model calls used. Keep the split only if the output is as good and the extra cost is acceptable for the value of the job.

Sources