Harness engineering / practical series

Design an agent team without creating a delegation loop

By Sandeep Belgavi · 18 October 2026

Use typed handoffs, capability checks and a shared budget to keep specialist teams accountable.

Specialists need explicit handoff conditions

A coordinator sends a coding request to a developer. The developer asks an architect, the architect asks a reviewer, and the reviewer returns the request to the coordinator. Each response sounds plausible, but no accepted artifact appears. Dividing work into roles does not define when work transfers, finishes or stops. Define those conditions before increasing the number of agents. Otherwise the team can spend more on coordination than on solving the task.

Make the handoff an inspectable record

Record the task identifier, source agent, destination role, required output, permitted resources, remaining budget and evidence references. Pass authorized artifact identifiers instead of copying every conversation. The receiving specialist must know whether it is giving advice or proposing an operation. A request to review a deployment plan should not inherit permission to deploy. Validate the handoff schema before invoking the destination model and preserve the accepted snapshot in the trace.

Use dependencies rather than conversation order

Some work is sequential: create a change, test it, then review the evidence. Independent read-only reviews of one immutable document may run in parallel. Parallel branches need separate working state and an explicit merge rule. Do not allow two agents to overwrite the same answer field. Preserve disagreement rather than averaging incompatible conclusions into a confident summary. The coordinator can request missing evidence or escalate an unresolved decision.

Bound the entire team

Giving each specialist five turns does not bound a team that can create unlimited specialists. Maintain a shared run budget alongside per-agent ceilings. Count transfers and repeated task-agent pairs. Permit a revisit only when meaningful new evidence justifies it, or require an explicit escalation. The visited-set exercise is deliberately stricter: it forbids all revisits. That simplicity helps reveal where a richer progress-based policy would be necessary.

Routing is not authorization

A router chooses a likely competent role. A policy layer decides whether that role may access these resources for this caller. Accurate routing cannot replace that check. Compare teams by accepted outcomes, unnecessary handoffs, budget exhaustion and evidence quality. Counting participating agents rewards activity rather than usefulness. A smaller team with clear contracts may be easier to evaluate and recover than a larger team with overlapping responsibilities.

Exercise the recovery boundary

Terminate a specialist after it has saved an artifact but before the coordinator receives the handoff result. On restart, the coordinator should discover the persisted artifact and its validation status. It should not blindly repeat the operation or trust a conversational claim that it completed. Include the artifact revision in the next handoff, and make a repeated transfer idempotent with respect to the same accepted task state.

Run the exercise

Download this Python exercise

Save the code as 07-agent-team-routing.py and run python 07-agent-team-routing.py with Python 3.11 or newer. This standard-library exercise uses synthetic data. It does not invoke a model or require an account, network connection or API key.

# Author: Sandeep Belgavi. Synthetic exercise; no network or provider calls.
allowed={"researcher","reviewer"}
seen=set()
remaining=3
def handoff(task,agent):
    global remaining
    key=(task,agent)
    if agent not in allowed or key in seen or remaining==0:return "STOP"
    seen.add(key);remaining-=1
    return "ACCEPT"
assert handoff("t1","researcher")=="ACCEPT"
assert handoff("t1","reviewer")=="ACCEPT"
assert handoff("t1","researcher")=="STOP"
assert handoff("t1","payment_writer")=="STOP"
print("two handoffs accepted; loop and unknown role stopped")

Expected output:

two handoffs accepted; loop and unknown role stopped

Change one assumption

Add an evidence revision to the handoff key. Permit one revisit only when the revision changes and the shared budget remains positive. Explain why a worker must not invent new evidence revisions just to reset the loop detector. A revision should refer to an independently persisted and validated artifact.

Implementation scope and further reading

This is an original AICassindra teaching design. The exercise demonstrates the stated invariant; it is not a complete production implementation. The local Harness Studio extension supports saved read-only agent teams, reviewed count-based routing and bounded sequential execution. Arbitrary imported graphs, effectful tools and automatic self-promotion remain unsupported.

All harness articles · Interactive boundary labs · Our public lab code