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

# 停止条件

> Goエージェントの処理を、ステップ数、トークン数、コスト、時間、ツール、終了理由で制限します。

`MaxSteps`は有用な安全策です。`StopWhen`を使うと、実行の進行に応じて評価される複数のプロダクト制限を組み合わせられます。

```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),
  },
})
```

`HasToolCall("publish_report")`や`FinishReasonIs("content_filter")`などのヘルパーもあります。判断がアプリケーションコンテキストに依存する場合は、独自の`StopCondition`も指定できます。

条件に一致したら、`result.Run.StopReason`、正規化された使用量の合計、最後に完了したステップを確認します。アプリケーションがエラーとして扱わない限り、停止は上限に達した正常な結果です。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.