> ## 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 Agent 运行。

组合停止函数，使产品限额不受模型是否继续的决定影响。

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