Interview prep
SmellControl-flow abusers

Subagent Recursion

Subagentes em Cascata

Subagent Recursion is an AI code smell, a sign of trouble in LLM systems, in the Control-flow abusers group. Subagents spawn subagents with no depth or cost limit.

Element
12/37
Level
Advanced
Read
4 min
Updated
On this page 7
  1. 01Signs and symptoms
  2. 02Reasons
  3. 03Cost of ignoring
  4. 04Treatment
  5. 05Payoff
  6. 06When to ignore
  7. 07Is it this smell?
  8. ··Quick answers

Signs and symptoms

An internal research tool got the question “what is the reimbursement policy for international travel?”. The trace (anonymized and condensed):

agent[0] delegate("research reimbursement policy")
  agent[1] delegate("research travel policy")
    agent[2] delegate("research international travel policy")
      agent[3] delegate("check applicable exchange rate")
        agent[4] delegate("research the dollar rate")
        ...
  agent[1] delegate("research reimbursement exceptions")
    ...
total: 140 subagents, 2,300 model calls, 47 minutes
answer: one paragraph that was on the wiki's first page

Every agent could spawn subagents, and so could every subagent. None had a depth limit, and each received a fresh budget.

An illustrative count makes the shape visible. Suppose 3 children per node and depth 5: 1 + 3 + 9 + 27 + 81 = 121 agents before the sixth level. If each makes 10 model calls, you are already past a thousand calls. The question fit in one search.

Signs of Subagent Recursion:

  • Subagents have the same delegation tool as the main agent.
  • There is no limit on depth or on the total number of agents per task.
  • Each subagent gets its own budget instead of sharing the parent’s.
  • The trace has deep trees for simple questions.
  • The cost of one task varies by orders of magnitude between similar runs.
flowchart TD
  A(["1. Agent"]):::llm --> B(["2. Subagent"]):::llm
  A --> C(["2. Subagent"]):::llm
  B --> D(["3. Sub-subagent"]):::llm
  B --> E(["3. Sub-subagent"]):::llm
  C --> F(["3. Sub-subagent"]):::llm
  D --> G(["4. and so on"]):::llm
  1. The main agent decides to delegate.
  2. Each subagent can delegate too.
  3. The tree grows at every level.
  4. With no limit, growth is exponential, and each node runs its own loop.

The design looks like team research. In practice, the model slices the question into ever thinner pieces (“exchange rate”, “dollar”, “PTAX”) instead of reading the wiki. Each slice gets a new agent, with its own history and its own cap.

Check +20 XP on first tryEach subagent can spawn up to 3 children, depth has no cap, and each node has 20 steps of its own. Which risk does the per-node cap not cover?

Reasons

  • Recursive delegation looks elegant. “The agent can spawn as many agents as it needs” sounds flexible. Flexible with no cap is unbounded.
  • The same configuration serves everyone. The subagent is a copy of the main agent, with every tool, including delegate. Whoever can spawn children spawns grandchildren.
  • Budget per agent, not per task. Each node has a reasonable cap; the total does not. Three levels of 20 steps look like 20. They are not.
  • Models tend to delegate when they can. With the tool available, they use it. Splitting the work is the most obvious way to “be an orchestrator”.
  • The framework limit misleads. LangGraph’s recursion_limit and the OpenAI Agents SDK’s max_turns cut the loop of one graph or one agent. They do not cut the depth of a tree of separate processes.

Anthropic’s “Building effective agents” (Dec. 2024) recommends stop conditions (a maximum number of iterations) on agent loops. The same principle applies to the tree: depth, width, and total cost.

Cost of ignoring

  • Explosive cost. A simple task can cost hundreds of times the normal amount. At 2,300 calls, even a cheap model eats the day’s quota.
  • Latency. Even in parallel, deep trees take a long time. Forty-seven minutes for a wiki paragraph.
  • Quality. Each level summarizes the level below. After four summaries, the reimbursement-policy detail became a generic paragraph, and an exchange rate nobody asked for slipped in.
  • Quota. Hundreds of simultaneous calls exhaust the whole system’s rate limit. Innocent other tasks fail with 429.
  • Diagnosis. A trace with 140 branches is almost unreadable. You find the final paragraph and cannot find the path that produced it.

Treatment

Refactoring Choose it when
Add Loop Budget Always. One budget per task, shared by the whole tree, with limits on depth and on the number of agents. Targets: Stop Conditions and Cost Budget.
Collapse Agents The tree exists out of habit, not need. One agent with the right tools solves it without delegating.

The tree budget has four numbers, all in code, none in the prompt:

  1. Maximum depth. Two levels cover most cases: one orchestrator and workers. Three already needs a justification.
  2. Maximum number of agents in the whole task.
  3. Shared cost and steps. Each child spends from the parent’s cap. When the cap is gone, the tree stops; it does not start a fresh budget.
  4. Who may delegate. Subagents, by default, do not inherit delegate. If a worker needs help, it returns the incomplete result.

Before and after, in the configuration:

# before
subagent.tools = parent.tools          # includes delegate
subagent.budget = Budget(steps=20)     # fresh, full

# after
subagent.tools = parent.tools - {delegate}
subagent.budget = parent.budget.share()
tree.max_depth = 2
tree.max_agents = 8

Internal policy research almost never needs a tree. One agent with wiki search, using the Subagent Delegation pattern with workers that lack delegate, is enough. The cascade is that pattern abused.

Check +20 XP on first tryYou removed delegate from children and capped depth at 2. One task still costs about 40 times the median, with 30 workers in parallel. What is the next cut?

Payoff

  • A maximum cost per task that you define.
  • Shallow trees, with delegation only where it isolates context or parallelizes work.
  • Answers that pass through fewer intermediate summaries.

When to ignore

Never leave recursion unbounded. Two-level delegation, with a shared budget and workers that lack delegate, is a legitimate design. Broad parallel research (several sources at once) fits that design. Subagents without the delegation tool solve most cases.

Is it this smell?

Check +20 XP on first tryThe main agent can spawn subagents, but subagents do not have the delegation tool. There is a limit of 8 subagents per task, and cost comes out of the parent's budget. Is this Subagent Recursion?

Check +20 XP on first tryEach subagent has a 20-step limit and can delegate up to 3 levels. There is no total budget. What is missing?

Check +20 XP on first tryAn agent runs a 200-turn loop without delegating to anyone, calling the same search. Which smell?

Check +20 XP on first tryAn orchestrator fires exactly 3 workers in parallel (statutes, figures, precedent), none of them can delegate, and the parent waits for all 3. Is this Subagent Recursion?

Quick answers

What is Subagent Recursion?

Subagent Recursion is an AI code smell, a sign of trouble in LLM systems, in the Control-flow abusers group. Subagents spawn subagents with no depth or cost limit.

How do you fix Subagent Recursion?

With Add Loop Budget and Collapse Agents. Each refactoring has safe step-by-step mechanics with an eval before and after.

Go further

Relations

Refactorings that treat it 2
Search