Understand first
New to this knowledge point
Complete the prerequisite concepts, read the principles and counterexamples, and then explain why in your own words.
Start with core principles →Understand → Implement → Debug → Design
Starting from the tool invocation loop, design termination conditions, budgets, cancellations, and verifiable completion statuses.
Knowledge content check2026-10-03 · Check the source of the original question2026-10-02
It is recommended to understand first:
Your first model call and response contract →Select the starting point based on the current basis, or you can go deeper one by one. When you encounter an unfamiliar concept, go back to the core principles first; use the knowledge exercises to check your understanding when you are finished.
New to this knowledge point
Complete the prerequisite concepts, read the principles and counterexamples, and then explain why in your own words.
Start with core principles →Prepare to write the principles into code
Understand implementation steps and boundaries, complete small tasks, and check results against acceptance requirements.
Reading implementation and trade-offs →Need to handle failures and changes in conditions
Follow the continuous questioning to locate the failure premise, and then compare the migration cases to explain how the plan should be adjusted.
Continue to delve deeper into the problem →Need to design or review plans
Combine engineering deductions and senior self-evaluation standards to explain the applicable conditions, costs and alternatives of the plan.
Analyze engineering scenarios →LEARN · PRACTICE · REFLECT
First read along the principles, Q&A and migration cases. When you need to check your understanding, switch to reinforcement exercises or start personal recording.
Can be practiced directly. After logging in, answers, favorites, and notes will be saved to your account.
Log in and saveEach modified commit will be kept as an independent history. Your level of mastery is up to you to evaluate yourself against the standards.
Core concept · Control and completion criteria in agent loops
Preparatory concepts:Request life cycle, Asynchronous cancellation, Business acceptance
Model output proposes the next step; the runtime owns execution and terminal state. Stopping only establishes that the loop ended. Success additionally requires evidence that the agreed business conditions hold. Budget exhaustion, cancellation, and unknown outcomes therefore need distinct labels rather than one generic 'completed' state.
The model proposes the next step; runtime enforces execution limits. Terminal labels preserve effects and uncertainty. Select the figure to open it at full size.
A conventional backend follows a defined program after receiving a request. An agent adds model-proposed next actions. The decision source changes, but server responsibilities for permissions, cost, and effects remain. The loop generates candidate actions, checks them at the gateway, executes them, and updates recorded facts. Final prose is a candidate artifact.
One round can make several calls, each with retries. Limiting rounds alone resembles limiting transactions without limiting their SQL operations. Bound model rounds, actual call attempts, concurrency, and absolute deadlines separately; account for actual usage. OpenAI Runner’s maximum turns protects the loop, while the application must enforce business budgets.
“Fixed” does not establish a passing test; “cancelled” does not erase a submitted release. Separate task state from operation states so a stopped task can retain completed effects and unresolved outcomes. A test model that declares completion early or repeatedly requests tools can expose control failures more reliably than one successful live-model run.
The model proposes actions; runtime executes permitted tools, returns results to context, and continues the loop. Runtime independently enforces permissions, rounds, time, and cost. Business evidence determines success. Budget exhaustion and tool failure are distinct terminal outcomes. Record the stopping reason and verified artifacts so users can see completed and outstanding work.
A response can contain an answer or several proposed tool calls. Runtime dispatches authorized calls, collects results, and decides whether to continue. OpenAI Agents Runner returns tool results to the model and bounds turns with max_turns. Count individual executions and internal retries independently. Supply goals, allowed actions, and evidence to the model while keeping identities, credentials, and authoritative budgets on the server.
Distinguish succeeded, failed, canceled, waiting_approval, and budget_exhausted. Success needs artifacts and passing checks; a completion claim is only a candidate. Bound model rounds, tool attempts, duration, and cost. Reserve estimated costs before calls and settle actual usage afterward through a shared ledger. Exhaustion preserves completed artifacts and outstanding work without unlimited retries.
Block new actions, then cancel supported running calls. Reconcile already-dispatched writes; a local timeout cannot establish non-execution. Separate transient failures, authorization denial, and permanent business errors. Retry only suitable idempotent operations. Repeated identical failures trigger diagnosis or termination. Record run_id, turn, tool_call_id, duration, and stop reason with payload redaction.
Use fixed model responses that repeat tools, propose parallel calls, declare success prematurely, or encounter cancellation. Assert limits stop dispatch, failures do not become succeeded, cancellation prevents new effects, and failed artifact checks lead to repair or explicit failure. Validate these controls before live-model completion measurements. Concrete counterexamples demonstrate implementation more clearly than a loop slogan.
Continue reading along with the premises and constraints of the problem. Understand the reference answers first, then try to put away the answers and explain the cause and effect and trade-offs in your own words.
Level 1One model round generates five tool calls, how to budget?
One round can contain multiple actions, so account for the abstract loop in the resource ledger.
Count one model turn and five candidate tool requests separately. Count each execution attempt that actually starts, including retries inside tools. Atomically reserve shared quota before starting; if it is insufficient, reject the batch or execute the permitted subset according to the task contract. Five concurrent branches must not each spend the same remaining balance. Return an explicit reason for unexecuted calls so the model does not mistake them for completed actions.
Follow this answer further
Level 2There are only two call quotas left, and there is a key verification among the five candidates. How should I choose?
Shared counting prevents overspending. Next, consider how to preserve meaningful acceptance checks when the remaining budget is insufficient.
Determined by task dependencies and priorities configured at runtime, the available budget for critical verifications is guaranteed first; the model is allowed to recommend ordering, but it cannot reduce verifications to optional on its own. If the full cost of a critical step is no longer affordable, it is more honest to save the current artifact and end with budget_exhausted than to claim success after performing two irrelevant steps.
Follow this answer further
Level 3A quota has been reserved for critical verification, but a started tool has not been returned. Can the budget be released?
Reservation policies must handle unknown outcomes by distinguishing local capacity from external facts.
Potential costs and side effects cannot be immediately dismissed as disappearing due to local wait timeouts. Settle confirmable resources separately, keep unknown operation records, and stop subsequent dependencies. The fee retention time and reconciliation method are determined by the supplier's behavior; the capacity will be released after the cancellation of cancellable pure calculations, and the receipt of the write request that has been issued will be checked first.
Level 1When the user cancels, the remote write operation has been successful. How do you end it?
Cancellation signals affect execution; business effects that already occurred require separate follow-through.
Disable new actions first, and then verify submitted requests. If the remote end has succeeded, it will record a receipt, telling the user that the subsequent steps have been cancelled, but the action has taken effect; if the business supports revocation, an independent operation is initiated based on the revocation permission, and whether it is successful is recorded. The original success record cannot be deleted, nor can the issuance of a compensation request be interpreted as restoration to the original status.
Level 1Is a correct answer successful if the model did not run the required tests?
The terminal state must be determined by acceptance conditions, rather than how credible the text sounds.
If the task contract requires running the test, it will not be judged as successful. Correct answers or code are only part of the conditions. If there is a lack of test evidence, it will be marked as to be verified. If there is still budget, make up the test. If there is no environment, the delivery scope and unverified items will be clarified. Only after the user explicitly adjusts the acceptance contract can it be completed according to the new scope, and the model cannot unilaterally delete the requirements.
First find out the conditions for change, and then determine which premises in the original plan still hold true. The following cases are teaching deductions to facilitate the transfer of principles to new problems.
Changing conditions:Acceptance changes from automatic testing to evidence coverage and manual judgment
Extended question:How to judge the completion of data research?
Start by defining the scope of coverage, the types of sources that must be consulted, how references can be read back, and how open questions are presented. References and required fields can be automatically checked during runtime, and disputed conclusions are submitted to manual or specialized review. Reaching the scope and truthfully reporting unknowns counts as completion. The model cannot be required to guarantee that nothing is missing in the world, nor can the number of searches be used as a substitute for evidence coverage.
The principles that remain unchanged:Completion always relies on predefined observable conditions, it's just that the validator changes from testing to evidence review.
Changing conditions:One task becomes multiple runs per day
Extended question:After today's failure, can yesterday's success status be automatically used tomorrow?
Each run binds a snapshot of the input with proof of acceptance. The facts published yesterday can be reused, today's data refresh, permissions and budgets are rechecked; the same business actions continue to use the same operation keys, and new date artifacts use new business identifiers. One success cannot overwrite a failure under new input, and the system should display the results of each run separately.
The principles that remain unchanged:Task lifecycle and business operation lifecycle must be separated.
It is designed based on public technical information; the reference materials support the technical mechanism, and the scenarios and scoring standards are designed by this website and do not represent the original interview questions of a certain company. New Q&A and migration cases are added for principle explanation, and source verification and case operation verification are recorded separately.
After reading, you can explain the principles, boundaries, and trade-offs against these standards. It is up to you to evaluate your mastery; if further verification is needed, complete the small tasks below.
Draw a state machine for a tool loop and simulate the model requiring the same failure action three times in a row.