Roles and contracts
Choose when to delegate independent work and define handoffs, shared-state rules and evaluation.
THE IDEA
Roles and contracts
Give each worker a concrete task, the resources it may use and the deliverable expected. The contract is also its whole authority: a worker can never hold more permission than the caller who delegated to it, so the allowed list is the overlap of what it asks for and what the caller has. Authority flows down the chain, never up.
The caller (orchestrator) holds: read, search. Choose what the worker asks for.
Give each worker a concrete task, allowed resources and a deliverable. A missing deliverable or an over-broad permission list is a contract problem to catch before work starts.
Predict first. Can a worker authorize an external write that the original task never allowed?
Chapter context
Delegation can divide a task into focused work units, but coordination creates costs and new failure paths. Add helpers when their independent contributions can be integrated and checked more clearly than one agent can do the work alone.
TRY IT YOURSELF
Part 1. Do it hands-on
Delegate permissions by hand, then write contract checks that clip a worker to its caller.
The caller (orchestrator) holds: read, search. Choose what the worker asks for.
Give each worker a concrete task, allowed resources and a deliverable. A missing deliverable or an over-broad permission list is a contract problem to catch before work starts.
- To do: The caller may read and search. A worker asks for read and write. How many permissions can the caller actually delegate (the overlap)?
- To do: Is the worker allowed to write? Type allow or deny
- To do: A task contract needs a task, allowed resources and a deliverable. A contract with only a task and allowed resources has how many problems?
- To do: Can a worker authorise an external write that the original task never allowed? Type yes or no
Part 2. Do it in code
- delegate(caller_perms, requested): the sorted list of requested permissions the caller itself holds (delegation cannot broaden authority).
- denied(caller_perms, requested): the sorted requested permissions that were refused.
- contract_problems(contract): contract is a dict; return "missing:task", "missing:allowed", "missing:deliverable" for absent or empty fields, in that order, and "allowed_not_list" if allowed is present but not a list.
- make_contract(task, allowed, deliverable, caller_perms): a contract whose allowed list is delegate(caller_perms, allowed) (so it can never exceed the caller's authority).
- can_act(contract, permission): True only if the permission is in the contract's allowed list.
Stuck, or something not working? You can come back to it any time.
CHECK YOUR UNDERSTANDING
Can a worker authorize an external write that the original task never allowed?
Chapter reference: math, worked example & code
This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.
Math and notation
With independent parallel task durations and merge time m, an ideal lower-bound schedule is , excluding orchestration overhead. If independent tasks each succeed with probability p, all n succeed with probability ; correlated failures invalidate that simple model.
Worked example
Three tasks take 2,5 and 3 minutes; integration takes 1. Ideal sequential duration is 11 minutes, while fully independent parallel duration is 6. Separately, three independent 90%-reliable components all succeed with probability 0.9^3=0.729. The latency gain does not itself establish a reliability gain.
Reference code
The following example uses the Python standard library and does not call a remote service.
from math import isclose
times,merge=[2,5,3],1
assert sum(times)+merge == 11
assert max(times)+merge == 6
assert isclose(.9**3,.729)
Python examples are provided for study and local execution; this page does not execute Python.
Common mistakes
Parallel workers need explicit ownership of shared artifacts. Agreement can reflect correlated failure. More agents can increase token usage and integration work even when wall-clock time falls.