Agent orchestration and resource budgets
Model a bounded agent as a state machine with explicit observations, permissions, verification, retries, and token-cost limits.
On this page
The question for today
What you’ll understand
- Distinguish a fixed workflow from a model-selected sequence of actions.
- Calculate worst-case cost and the effect of repeated attempts under stated assumptions.
- Design termination, checkpointing, and verification boundaries for multi-step tasks.
An agent system repeatedly observes a state, proposes an action, receives a result, and decides what to do next. Workflows fix more transitions in code; agents delegate more selection to models. Neither arrangement removes the need for explicit state and limits. Ask which decisions need model judgment, which can be deterministic, and what external evidence proves task completion.
Make the action loop inspectable
Represent the task with durable state: objective, accepted constraints, completed operations, unresolved questions, resource use, and authoritative artifact identifiers. Tool results are observations, not proof of success. ReAct explores interleaving reasoning and actions, but the application still owns capabilities and execution. A fixed retrieval-and-formatting workflow can be easier to test when its steps are known.
Each transition needs a precondition, allowed action set, validation, and a recorded outcome. Keep external side effects idempotent or reconciled through an operation ledger. If a process restarts, reload committed state rather than reconstructing it solely from a conversation summary. Parallel workers can accelerate independent tasks, but shared mutable state creates conflicts and duplicate actions. Assign ownership and merge rules, and verify child results before allowing their claims to determine a final answer.
Budget the entire trajectory
A single model call has input and output tokens, while a trajectory adds tool charges, retries, growing context, and worker calls. Set hard limits for tokens, money, elapsed time, actions, and concurrent work. Reserve budget for verification and a useful final report instead of spending everything on exploration. A step cap is insufficient if one operation has unbounded output or duration. Bound each operation as well as the loop.
The expected cost of a retry policy depends on how often it continues and how much each attempt costs. Independence is often a poor assumption: the same misunderstood requirement can cause every attempt to fail. Repeated-sampling formulas require stated assumptions, and verifiers can themselves be wrong. Distinguish pass-at-k, which asks whether any attempt succeeded, from a deployed selector's ability to identify that attempt. More generations do not help if the system cannot recognize correct work.
Terminate on verified outcomes or explicit limits
Define success through an external criterion: a test passes, a requested artifact exists and meets its contract, or an authoritative service confirms the operation. The model saying done is not that criterion. Define failure and partial completion too. If a deadline expires, preserve completed work and report remaining tasks with evidence. A precise partial outcome is useful when a required dependency remains unavailable.
Evaluate full trajectories on representative multi-step tasks, including tool outages, ambiguous instructions, and policy constraints. Tau-bench studies tool-agent-user interactions and motivates examining reliable task completion across repeated trials. Its domain-specific scores are not a guarantee of general agent capability. Review traces for needless loops, stale observations, unauthorized proposals, and missing verification. Add autonomy where measured benefits justify its cost, with narrow, auditable boundaries.
Work it through
Set a worst-case task cost
Use fictional planning rates of 2 currency units per million input tokens and 8 per million output tokens. Each round is capped at 1,200 input and 400 output tokens plus a 0.01-unit tool call. A task permits at most four rounds; assume every round reaches its cap.
One round's input cost is 1,200×2/1,000,000=0.0024 units. Its output cost is 400×8/1,000,000=0.0032 units.
Add the tool cost: 0.0024+0.0032+0.01=0.0156 units per round. Four rounds cost at most 4×0.0156=0.0624 units under these stated caps.
At 100,000 tasks per day, the capped trajectory spend is 6,240 units per day. This excludes fixed infrastructure and any separately budgeted evaluator. If the context grows beyond 1,200 tokens, the original bound no longer holds.
A useful cap constrains actual serialized input and every paid call, including child workers. The rates are invented for arithmetic practice, not current provider prices.
The living notebook
Explore the model
Interactive lab · queue
Retries consume shared capacity
Vary arrival λ and service μ in the fluid backlog max(0, 4+(λ−μ)t). Interpret arrival as total admitted work, including retries. The separate M/M/1 readout requires stable Poisson/exponential single-server assumptions; this lab does not simulate agents, branching workflows, or retry timing.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forRepeated attempts are additional load, so a retry policy must fit both a per-task budget and the system's capacity.
Pause & reason
Check your understanding
Your turn
Try it yourself
A task allows three rounds, each capped at 2,000 input and 500 output tokens, at the fictional rates 2 and 8 units per million respectively. Tools cost 0.02 units per round. Compute the maximum modeled task cost and name a condition that breaks the bound.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute one complete round, then multiply by the maximum round count; include tool charges.
Compare with the solution
Input costs 0.004 units and output costs 0.004, so each round totals 0.028 with tools. Three rounds cost at most 0.084 units. An uncounted child model call, larger serialized context, an additional paid evaluator, or more tool calls than capped would break this accounting. Reserve those operations explicitly rather than assuming they are free.
Keep the idea
Take it with you
- A bounded agent is an explicit state machine with application-owned action permissions.
- Budget all serialized tokens, tools, retries, workers, and verification.
- Finish on external evidence of success or report a precise partial result at the limit.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.