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.

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.
Before you begin
Access to the run state and the model or agent termination information.
Key concepts
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
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
Read the run’s state and finish reason.
Inspect the final tool call and any pending input.
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.
Related resources
Was this helpful?

