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

`MaxSteps` is a useful safety net. `StopWhen` adds composable product limits that are evaluated as the run progresses.

```go theme={null}
agent := phaseoagent.CreateAgent(phaseoagent.AgentDefinition{
  ID: "bounded-research",
  Model: "openai/gpt-5.4-nano",
  StopWhen: []phaseoagent.StopCondition{
    phaseoagent.StepCountIs(12),
    phaseoagent.MaxTokensUsed(40_000),
    phaseoagent.MaxCost(2.50),
    phaseoagent.MaxDuration(2 * time.Minute),
  },
})
```

Other helpers include `HasToolCall("publish_report")` and `FinishReasonIs("content_filter")`. You can also provide a custom `StopCondition` when the decision depends on application context.

When a condition matches, inspect `result.Run.StopReason`, the normalized usage totals, and the last completed step. Stopping is a successful bounded outcome unless your application chooses to treat that reason as an error.
