組み込みの上限を組み合わせる
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.
ステップ数、トークン数、コスト、時間、ツール呼び出し、終了理由でエージェントの処理を制限します。
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) | 累積トークン使用量が上限に達した |
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],
});