Enforce completion, no-progress detection, and resource budgets outside the prompt.
Section 2.1 1 of 7
Overview
Focus
Enforce completion, no-progress detection, and resource budgets outside the prompt.
Your route through the lesson
2.2 Success, failure, and clarification states
2.3 Step, time, token, and cost budgets
2.4 Repeated actions and no-progress detection
2.5 Put it into practice
2.6 Guided comparison
2.7 An expensive call within a short loop
All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.
Section 2.2 2 of 7
Success, failure, and clarification states
Focus
Define terminal outcomes that distinguish success, failure, and missing information.
Termination means the runtime stops selecting new actions. It needs a reason. Success means the declared task condition was observed. Failure means the task could not be completed under the allowed process. Clarification means a required input is missing or ambiguous and the user must supply it. These outcomes should be explicit fields rather than inferred from a polite final sentence.
For a lookup, an ok result for the requested service can support success. An invalid service name may require clarification. A permission denial is a failure or blocked outcome under the application’s policy, not an invitation to keep trying alternate identities. The runtime should preserve the denial and avoid converting it into “not found.”
A completion condition must be checkable. “Be helpful” is too broad; “return the observed status for the requested service or an explicit unconfirmed result” is concrete. A model can propose that it is done, but the program checks that the condition holds. This prevents fluent summaries from silently redefining success after an unsuccessful attempt.
// Quick review
Check your understanding.
Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.
Section 2.3 3 of 7
Step, time, token, and cost budgets
Focus
Enforce step, elapsed-time, token, and cost limits before expensive actions.
A step budget limits decision cycles. A call budget limits tool invocations. An elapsed-time budget limits wall-clock duration. A token budget limits model input and output units, and a cost budget limits estimated or billed spending. These limits measure different resources: a single action can be slow or expensive even in a short loop.
Suppose a task allows four decisions, two tool calls, and five cost units. The first lookup costs two units. A proposed second call has a reserved maximum of four units. Two plus four exceeds five, so the executor refuses it before starting. A retrospective check after the call cannot undo the expense.
Use a monotonic clock for elapsed duration, because it measures progress without being affected by wall-clock adjustments. Set a per-call timeout no larger than the remaining task deadline. Token and cost estimates can be uncertain, so reserve a conservative upper bound where available and reconcile actual usage afterward. The deterministic lab uses simulated cost units and a controlled clock; it makes no claim about a provider’s actual bill.
// Quick review
Check your understanding.
Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.
Section 2.4 4 of 7
Repeated actions and no-progress detection
Focus
Detect repeated actions that consume resources without changing the state.
No progress means the runtime keeps acting without getting closer to its checkable goal. One useful detector compares a normalized action signature and its result. A signature includes the action name and meaningful arguments. If the same action repeatedly returns the same failure with no changed input, another identical attempt is unlikely to help.
Suppose a directory lookup for missing-service returns not_found three times. The model keeps asking for the identical lookup. After the configured repetition threshold, the runtime stops with no_progress. It preserves the three observations and does not claim that repeated attempts eventually proved success.
Not every repeated call is wrong. Polling a genuinely running operation can be justified when the operation contract allows it, a delay is used, and total polling remains bounded. A retry after a documented transient error may also be useful. The rule therefore combines signatures with observed state and policy. Budgets remain a final safeguard even if the progress detector misses a creatively reworded version of the same unproductive action.
// Quick review
Check your understanding.
Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.
Section 2.5 5 of 7
Put it into practice
Focus
Run failing and successful loops and inspect enforced resource limits.
Save week09.py in your exercise folder and run python week09.py --lesson 2. The lab uses an always-failing synthetic tool, a successful lookup, an expensive proposed call, and a fake clock that advances deterministically. No real spending or network access occurs. The output lists termination reasons and measured call counts.
A guard evaluates the next call before the dispatcher runs. Here a proposed cost of four is rejected after two units have been used:
used = 2
maximum = 5
reserved_next = 4
allowed = used + reserved_next <= maximum
assert allowed is False
The operator <= means less than or equal to. The weekly runtime also checks decision and call counts, elapsed time, and repeated signatures. Expect the failing loop to stop within the declared call maximum, the expensive call to remain undispatched, and the valid lookup to complete with an observed result. These assertions verify executor limits for scripted decisions. They do not measure how often a real model finds a useful next action.
Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.
Section 2.6 6 of 7
Guided comparison
Focus
Read stopped traces without confusing a budget boundary with task completion.
The completed failure trace permits at most three tool calls. Each returns the same not_found observation. The runtime stops with no_progress at the repetition threshold, while the call count remains three. No successful observation exists, so the final outcome is unsuccessful even though the stopping mechanism worked correctly.
The expensive-call trace allows five cost units. It records two used units and a proposed reservation of four. The guard stops with cost_budget before dispatch; the tool-call count does not increase for that denied proposal. Counting proposals and executed calls separately makes this visible.
The successful trace gets an ok lookup within all budgets and ends completed. Its report includes one successful task, one call, and the actual termination reason. Together these cases show that a runtime can pass its engineering checks when some tasks intentionally fail. The acceptance condition is honest bounded behavior, not a fabricated success for every input. When evaluating a real model later, report task success rate alongside budget stops and no-progress stops.
// Quick review
Check your understanding.
Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.
Section 2.7 7 of 7
An expensive call within a short loop
Focus
Stop a short loop whose next action exceeds the spending budget.
A research agent has made only one decision, so its ten-step budget appears generous. Its next proposed analysis call would process a very large document. The declared cost ceiling is eight units, three have already been spent, and the new call’s reserved upper bound is six. The prospective total is nine, exceeding the ceiling.
The completed executor refuses the call before dispatch and records cost_budget. It can offer a bounded alternative, such as analyzing a smaller authorized excerpt whose reservation fits the remaining five units. The alternative still needs its own validity and usefulness checks; it is not automatically correct merely because it is cheaper.
This transfers the idea of independent budgets to practical systems. Step counts bound repeated decision-making but cannot bound a single large request. The same pattern applies to a file-size limit, a maximum number of returned rows, or a per-operation mutation cap. Every limit must be enforced at the component that controls the resource, so a prompt request to “stay cheap” supplements rather than replaces an actual dispatch guard.
// Quick review
Check your understanding.
Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.
Your personal notes
Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.
Optional public reference; internet, no account. time is a standard-library module; the core tests use a deterministic clock fixture and no paid calls.
Ask your own AI assistant
Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.