> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/technical-reference/models-agents-and-skills/agent-execution-limits-and-stop-conditions.md).

# 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](https://1957915746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FQq9BwGaO0a4ZeL7HvIDq%2Fagent-execution-limits-and-stop-conditions.png?alt=media)

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.

<details>

<summary>Copy the example</summary>

```python
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)
```

</details>

## 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.

## Related resources

[Model Settings and Supported Capabilities](https://docs.stackai.com/technical-reference/models-agents-and-skills/model-settings-and-supported-capabilities.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/technical-reference/models-agents-and-skills/agent-execution-limits-and-stop-conditions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
