> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Stop conditions

> Bound Python agent work by steps, tokens, cost, duration, tools, or finish reason.

Compose stop helpers through `stop_when`:

```python theme={null}
stop_when = [
    step_count_is(12),
    max_tokens_used(40_000),
    max_cost(2),
    max_duration(60_000),
]
```

Additional helpers include `has_tool_call(...)` and `finish_reason_is(...)`. Keep a step or duration bound even when using cost or token limits because those depend on reported usage.

## Related

* [Dynamic turns](./agent-sdk-dynamic-turns)
* [Outputs and retries](./agent-sdk-run-controls)
