OBLYTECH Logo
OBLYTECH Logo

Step Limits for Agent Task Loops

To limit agent steps per task, define a shared budget for tool calls, count attempts before dispatch, and set smaller retry allowances within that budget. Enforce the cap outside the agent’s instructions. When the budget runs out, block further actions, preserve confirmed results, and hand unfinished work to an accountable reviewer.

Define the task boundary before counting steps

A step limit needs a clear unit of work. Describe the requested outcome, the records the agent may touch, and the evidence required to call the task complete. “Investigate this incident and propose a next action” has a different boundary from “resolve related incidents.” An open outcome makes it hard to distinguish necessary investigation from an expanding loop.

Give the task a durable identifier that follows its work across workers, restarts, and delegated actions. Keep the original scope attached to that identifier. A worker replacement should inherit the remaining allowance rather than receive a fresh budget. Otherwise, restarting a stalled run becomes an unintended way to extend its authority.

Define a step as an attempted tool operation admitted by the execution controller. Count unsuccessful calls and repeated reads because they consume execution capacity too. Track model reasoning turns separately if they can loop without calling a tool. Pair the operation budget with an elapsed time boundary so waiting cannot keep a task active indefinitely.

Choose how to limit agent steps per task

Start by walking through a successful task manually. List the operations needed to gather evidence, make a decision, perform an authorized change, and verify the outcome. Add a bounded allowance for plausible recovery. Use that sequence to propose a cap, then test it against representative tasks before granting unattended execution.

Keep the following allowances distinct in the task policy:

  • Total operations: the shared ceiling across reads, writes, retries, and delegated work.
  • Repeated attempts: a smaller allowance for retrying the same operation after a qualifying failure.
  • Changes: a separate ceiling for operations that alter records or trigger downstream work.
  • Elapsed time: a deadline covering execution, waiting, and recovery.

These allowances should overlap rather than add together. A retry consumes both a retry allowance and a total operation allowance. A write retry also draws from the change allowance. Reaching any applicable boundary should prevent that operation from starting, even when another allowance still has capacity.

For example, an illustrative incident task might allow twelve total operations and two retries within that total. If it has already used eleven operations, a remaining retry allowance does not authorize two more calls. These numbers describe a policy example, not a recommended default. Select limits from the task’s scope and the consequences of failure.

Enforce the budget at the execution boundary

Put the admission check where a tool request becomes executable. Instructions can tell an agent to stop, but the controller should decide whether a requested operation fits the remaining budget. Bind the policy to the task record so tool arguments, retrieved text, or a revised plan cannot change it.

  1. Read the task’s remaining allowance and current stop state.
  2. Check whether the proposed operation is allowed and whether its outcome can still be verified.
  3. Reserve the required capacity before sending the request.
  4. Record the attempt and its result against the same task identifier.
  5. Reject further dispatch once a relevant boundary is reached.

Make reservation a single coordinated operation when calls can run in parallel. Two workers reading the same remaining balance should not both spend the final available step. Give delegated workers a share of the parent’s allowance, and include tool wrapper retries in the accounting. Document which component owns each counter to avoid gaps and double counting.

Keep authorization separate from capacity. A task with steps remaining still needs permission for the action it proposes. Use AI security and access design to define those action boundaries. Budget enforcement then controls how much permitted work can proceed within them.

Retry according to the failure, not the remaining balance

A retry needs a reason to expect a different result. A temporary connection failure may justify another attempt after a bounded delay. A denied permission, invalid target, or rejected business condition calls for a decision or correction. Repeating the unchanged request spends the budget without resolving the cause.

Before retrying a change, determine whether the previous attempt took effect. A timeout can leave the outcome unknown. Record that uncertainty and use an approved verification method where available. If the budget cannot support verification, stop with an unknown outcome rather than blindly submitting the change again.

Group retries by the intended operation, not by the exact wording of arguments. Changing a search phrase or rebuilding a request should not erase its failure history. Also detect repeated cycles, such as searching, reopening the same record, and searching again without new evidence. Stop such cycles before they consume the full allowance.

Treat instructions found inside records as task data rather than authority to extend execution. Text that asks the agent to retry indefinitely or delegate more work must not alter the budget. Review prompt injection risks in ITSM records when defining how retrieved content influences the next step.

Plan the final operations before the cap is reached

Set a warning threshold that leaves room to finish a controlled sequence. At that point, compare the remaining allowance with the operations needed to complete and verify the next change. If the sequence no longer fits, save the proposed action for review instead of beginning a change that cannot be checked.

Handle in-flight work explicitly. Reaching the cap should block new dispatches; it does not establish that an already submitted request has stopped. Track pending operations until their outcomes are known or marked unresolved. Prevent the agent from interpreting a blocked next step as proof that earlier work was rolled back.

Save a handoff record containing the requested outcome, confirmed changes, unresolved requests, unused proposals, and the reason execution stopped. Distinguish verified completion from partial completion. Tell the requester what remains and identify the team or person responsible for the next decision. Avoid a generic success message that hides unfinished work.

Produce the stop record through the controller’s logging path rather than an extra agent tool call after exhaustion. If recovery requires additional external operations, define their authority and allowance in advance. Keep rollback decisions separate: reversing a change can create new effects and should follow an approved recovery procedure.

For help planning this work, see AI and ML services.

Test exhaustion and review budget changes

Test the boundary directly, including a task that needs exactly the permitted operations and one that requests another. Check concurrent calls competing for the final slot, retries hidden inside a tool wrapper, delegated work, and a restart after a partial change. Confirm that each scenario produces the expected counter and stop record.

Include a case where a change succeeds but its response is lost. The expected result should preserve uncertainty until verification, without duplicate execution. Also test malicious record text asking for a larger allowance. These checks establish whether the controller enforces the policy independently of the agent’s generated plan.

Review stopped runs by cause. Separate limits reached through necessary investigation from repeated failures, expanding scope, and weak completion criteria. Compare those findings with tasks that completed correctly. Raising a cap can be justified, but first identify which additional operations would help and how their outcomes would be assessed.

Record the policy version with the task so reviewers can reconstruct the applicable rules. Assign a named owner to approve changes to limits and retry conditions. Use AI observability and human oversight to connect execution records with review decisions and follow-up ownership.

Questions about exceptions and resuming stopped tasks

Should a user cancellation restore unused steps?

Treat cancellation as a separate terminal decision. Preserve the unused balance for audit purposes, but do not make it an invitation to resume automatically. A later request should identify whether it continues the same task or starts a separately authorized outcome.

Can an urgent task receive a larger allowance?

Define an exception route with a named approver, a reason, and an expiry. Urgency should trigger a deliberate authorization decision. Capture the revised scope and allowance before execution continues so the exception can be reviewed afterward.

How should scheduled waiting affect the count?

Distinguish passive waiting from repeated status requests. A scheduled wake-up can preserve the existing task budget while its deadline remains applicable. Polling that invokes a tool should consume capacity; otherwise a waiting loop can escape operation accounting.

What if the task changes while it is paused?

Compare the revised request with the saved scope and confirmed effects. A new objective may need a new task with an explicit relationship to the original. Carry forward unresolved operations so a replacement task does not unknowingly repeat them.