Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

action space
The full set of moves an agent can choose from, usually the list of tools it is given.
agent
A program that repeats a loop: read the state, choose a move, look at the result, then decide again.
budget
A hard limit on how many steps, seconds or moves a run may spend before it must stop.
delegation
Handing a smaller task to another agent, with its own instructions, tools, budget and required result shape.
guardrail
Code that checks a proposed move against the rules before it runs, and can refuse it or ask a person.
loop
The repeated cycle of choosing a move, carrying it out and reading the result, which makes a program an agent.
model
The trained program that reads text and chooses what to say or do next.
observation
What came back from a tool or a step, added to the state for the next decision.
plan
A written list of steps for the task, which can be revised when a step fails or the facts change.
scratchpad
The working notes for one run: the plan, what was tried and what came back, discarded when the run ends.
state
The record of the question, the plan and the observations so far, passed to the model on every turn.
sub-agent
A separate agent given one bounded job, its own tools and its own budget, whose answer returns to the caller.
tool
A named function an agent may ask to run, with declared inputs and a result the loop can read.
trace
The ordered record of every decision, tool use and result in a run, used to explain what happened.

AI agents from the ground up

Delegation and handoffs

A sub-agent is a function call with a prompt. It earns its cost when the subtask has its own tools and its own context — and it needs a contract, a budget and a way to fail.

Part 7 of 10

Advanced15 min readBack to Courses

Delegation is a context boundary

The main reason to delegate is not specialisation, it is context. A subtask that needs twenty documents and one answer can do that work in its own window and return a paragraph, leaving the parent’s context clean.

That is also the cost: the parent cannot see the work, only the result. If the result is wrong, the parent has no way to tell whether the subtask failed or the question was wrong.

Picture a parent agent answering “what is our refund policy for gift cards”. It delegates to a research agent with the policy index, which reads twenty passages and returns three findings with sources. The parent never sees the twenty passages, which is the benefit. It also cannot see that two of them contradicted each other, which is the risk, and why the result needs a confidence and a stopped reason rather than a paragraph.

Give the sub-agent a contract

A handoff should state the goal, the inputs, the allowed tools and the shape of the result. That is the same four-part prompt from the first course, applied to an agent instead of a model call.

The result shape matters most. “Return a summary” gives the parent a paragraph it has to interpret. “Return findings, sources and confidence” gives it a value it can branch on.

The contract should also say what the sub-agent must not do. “Do not write to the index”, “do not contact the customer”, “do not spend more than five steps” are boundaries the parent can enforce even if the child ignores them. The child’s prompt states them; the parent’s code checks them. A contract that only lists the goal is a wish, not a delegation.

A handoff with a contract

result = research_agent.run(
    goal="Find the refund window",
    inputs={"policy_id": "billing#refunds"},
    tools=["search", "read"],
    budget={"steps": 5},
)
# {"findings": [...], "sources": [...], "confidence": 0.8, "stopped": "answered"}

A result the parent can use

Run the handoff, then make the sub-agent return a plain string instead of the structured result. Notice how much harder the parent’s decision becomes.

Output
Click "Run" to execute your code

The handoff is a contract, not a conversation

The parent should be able to branch on the result without reading it. A handoff that returns findings, sources, confidence and a stopped reason gives the parent four facts: what was found, where it came from, how much to trust it, and whether the sub-agent finished. A handoff that returns a paragraph gives the parent text and hope.

A common mistake is letting the sub-agent decide the shape of its answer. It writes a helpful summary, the parent parses it with a regular expression, and the first reworded summary breaks the parent. Fix the shape in the contract, validate it at the boundary, and let the sub-agent spend its freedom on the research rather than on formatting.

The sub-budget is not optional

A delegated agent that can spend without limit is a way to turn one request into an unbounded bill. Give it its own step and token budget, smaller than the parent’s remaining budget, and treat exhaustion as a normal result.

The parent should also keep a global budget. A sub-agent that returns “out of budget” is a signal to stop delegating, not to try again with a bigger allowance.

Do not give a sub-agent more permissions than the parent. Delegation must not be a way to escalate: the effective permission is the intersection, never the union.

When one agent is enough

Splitting into agents adds a contract, a budget, a failure path and a place for the result to be misunderstood. It pays when the subtask is genuinely separable: different tools, different context, different owner.

If the subtask shares the parent’s tools and context, it is a function. Call it as one and skip the ceremony.

A useful test is to write the handoff contract. If you cannot name a result shape that the parent needs and the child can produce, the subtask is not separable yet. If the contract is just the parent’s question restated, you are paying for a second context to do the same job. The test is cheap and it happens before you build the second agent, which is the right time to discover that you do not need one.

Permissions do not grow by delegating

The parent has read-only tools. Run the check, then give the sub-agent a write tool and confirm the effective permission is still the intersection.

Output
Click "Run" to execute your code

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

What is the main benefit of delegating to a sub-agent?