组合内置限制
status: "stopped" 的运行结果。
可用辅助方法
添加自定义条件
条件可以返回false、true 或原因字符串:
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
按步骤数、token 数、成本、时长、工具调用或结束原因限制 Agent 工作。
import {
maxCost,
maxDuration,
maxTokensUsed,
stepCountIs,
} from "@phaseo/agent-sdk";
const agent = createAgent({
id: "bounded-research",
stopWhen: [
stepCountIs(12),
maxTokensUsed(40_000),
maxCost(2),
maxDuration(60_000),
],
});
status: "stopped" 的运行结果。
| 辅助方法 | 停止条件 |
|---|---|
stepCountIs(limit) | 已完成步骤数达到上限 |
maxTokensUsed(limit) | 累计 token 用量达到上限 |
maxCost(limit) | 已报告的累计成本达到上限 |
maxDuration(ms) | 运行时间达到时长上限 |
hasToolCall(name) | 某个步骤包含指定的工具调用 |
finishReasonIs(reason) | 模型步骤报告了结束原因 |
false、true 或原因字符串:
const stopAfterRepeatedFailures = ({ steps }) => {
const failures = steps.filter((step) => step.status === "failed").length;
return failures >= 2 ? "repeated_failures" : false;
};
const agent = createAgent({
id: "support-agent",
stopWhen: [stepCountIs(10), stopAfterRepeatedFailures],
});