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

# 停止条件

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

停止関数を組み合わせ、自律的な処理をアプリケーションの予算内に収めます。

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

ツール呼び出しや終了理由に対する条件も利用できます。完了後に`result.run.stop_reason`と正規化された使用量を確認し、予算による停止とモデルの通常終了を区別します。

停止は上限に達した結果であり、自動的に例外になるわけではありません。成功扱い、再試行、ユーザーへの表示のどれにするかを理由ごとに決めてください。


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