> ## 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 Ruby agent runs by steps, tokens, cost, duration, tools, or finish reason.

Combine stop helpers to keep autonomous work inside application budgets.

```ruby theme={null}
agent = PhaseoAgentSdk.create_agent(
  id: "bounded-research",
  model: "openai/gpt-5.4-nano",
  stop_when: [
    PhaseoAgentSdk.step_count_is(12),
    PhaseoAgentSdk.max_tokens_used(40_000),
    PhaseoAgentSdk.max_cost(2.50),
    PhaseoAgentSdk.max_duration(120_000)
  ]
)
```

Tool-call and finish-reason conditions are also available. Inspect `result.run.stop_reason` and normalized usage after completion to distinguish a budget stop from a normal model finish.

Stopping is a bounded outcome, not automatically an exception. Decide which reasons should be successful, retryable, or shown to the user.
