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

# 停止条件

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

モデルが続行するかどうかの判断に関係なく、プロダクトの予算を守るため停止関数を組み合わせます。

```php theme={null}
$agent = AgentSdk::createAgent(new AgentDefinition(
    id: "bounded-research",
    model: "openai/gpt-5.4-nano",
    stopWhen: [
        AgentSdk::stepCountIs(12),
        AgentSdk::maxTokensUsed(40000),
        AgentSdk::maxCost(2.50),
        AgentSdk::maxDuration(120000),
    ]
));
```

SDKにはツール呼び出しや終了理由に対する条件もあります。実行完了後に`$result->run->stopReason`と正規化された使用量を確認すると、アプリケーションで予算による停止とモデルの通常終了を区別できます。

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


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