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

# रोकने की शर्तें

> Agent work को steps, tokens, cost, duration, tool calls या finish reason से सीमित करें।

हर एजेंट के लिए स्पष्ट निष्पादन बजट तय करने हेतु रोकने की शर्तों का उपयोग करें। इन शर्तों का मूल्यांकन पूरे हुए चरणों और कुल उपयोग के आधार पर किया जाता है।

## अंतर्निहित सीमाएँ मिलाएँ

```typescript theme={null}
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),
  ],
});
```

पहली matching condition अपना reason दर्ज करती है और `status: "stopped"` वाली run लौटाती है।

## उपलब्ध हेल्पर

| सहायक फ़ंक्शन | कब रुकता है |
| - | - |
| `stepCountIs(limit)` | Completed step count limit तक पहुँच जाए |
| `maxTokensUsed(limit)` | Cumulative token usage limit तक पहुँच जाए |
| `maxCost(limit)` | Reported cumulative cost limit तक पहुँच जाए |
| `maxDuration(ms)` | Elapsed runtime duration तक पहुँच जाए |
| `hasToolCall(name)` | किसी step में दिया गया tool call मौजूद हो |
| `finishReasonIs(reason)` | Model step finish reason बताए |

## कस्टम शर्त जोड़ें

Condition `false`, `true` या reason string लौटा सकती है:

```typescript theme={null}
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],
});
```

Operators या product UI को run समाप्त होने का कारण समझाना हो तो reason string बेहतर है।

## संबंधित गाइड

* [डायनामिक टर्न](./agent-sdk-dynamic-turns.mdx)
* [आउटपुट और पुनः प्रयास](./agent-sdk-run-controls.mdx)
* [लाइफसाइकल हुक](./agent-sdk-lifecycle-hooks.mdx)


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