For the complete documentation index, see llms.txt. This page is also available as Markdown.

Agent Execution Limits and Stop Conditions

An agent can stop because it completed the task, reached an execution limit, paused, failed, or was canceled. Use the reported state to decide what happens next.

Choose the next action from the actual run state

Illustrative v2 client logic; helpers are application code. A successful run state does not replace checking output quality or any reported truncation. Do not turn an absent finish reason into a claim of normal completion.

Copy the example
if run.state == "succeeded":
    inspect_output_and_reported_finish_reason(run)
elif run.state == "paused":
    display_pending_human_request(run)
elif run.state in {"failed", "cancelled"}:
    show_final_state_and_available_details(run)
else:
    continue_following_the_same_run(run.id)

Before you begin

Access to the run state and the model or agent termination information.

Key concepts

Term
Definition

Finish reason

Information indicating why generation ended, when the provider supplies it. Distinguish normal completion from a length limit, interruption, or unreported reason.

Paused

A run state that waits for a supported response before it can continue. Respond to the existing run instead of starting a new one.

Terminal state

A state indicating that a run has ended, such as succeeded, failed, or cancelled. Stop normal completion polling only after a final state is known.

Configuration options

Option
Purpose
Behavior

Execution limit

A cap on a run, model response, tool sequence, or other processing resource.

Identify which limit was reached before adjusting another setting.

Output limit

A cap on generated response length.

Reaching it can truncate the response; it does not increase available input context.

Set agent execution limits

  1. Read the run’s state and finish reason.

  2. Inspect the final tool call and any pending input.

  3. Continue, recover, or cancel through the control appropriate to that state.

Your interface distinguishes a completed answer from a partial or interrupted one.

Behavior and limitations

An output-length limit can truncate a response. An unknown or unreported finish reason must not be rewritten as normal completion. Tool-specific step limits, model output limits, and workflow deadlines are separate controls. Raising one limit does not repair a loop that repeatedly chooses the wrong action.

Model Settings and Supported Capabilities

Was this helpful?