Combine built-in limits
status: "stopped".
Available helpers
Add a custom condition
A condition can returnfalse, true, or a reason string:
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Bound agent work by steps, tokens, cost, duration, tool calls, or finish reason.
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".
| Helper | Stops when |
|---|---|
stepCountIs(limit) | The completed step count reaches the limit |
maxTokensUsed(limit) | Cumulative token usage reaches the limit |
maxCost(limit) | Cumulative reported cost reaches the limit |
maxDuration(ms) | Elapsed runtime reaches the duration |
hasToolCall(name) | A step contains the named tool call |
finishReasonIs(reason) | A model step reports the finish reason |
false, true, or a reason string:
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],
});
Was this page helpful?