> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Restart Loop Guard • AI Agent SDK

> RestartLoopGuard: Pure rolling-window predicate that trips on a rapid restart loop.

# RestartLoopGuard

> Defined in the [**protocols**](../modules/protocols) module.

<Badge color="blue">AI Agent</Badge>

Pure rolling-window predicate that trips on a rapid restart loop.

A companion to :func:`classify_exit_reason` for the crash-loop breaker
referenced in Issue #3021. Where `classify_exit_reason` maps a *single*
exit to a supervisor exit code, this tracks the *rate* of restart-worthy
boots so a process that keeps crashing-on-resume can stop auto-resuming the
offending work rather than wedging in a tight restart loop.

It is intentionally side-effect free (records timestamps only, no I/O, no
heavy deps) so both gateway runtimes (`BotOS` and `WebSocketGateway`)
can reuse the same *decision* and prove it in isolation. The caller feeds a
monotonic timestamp each time a restart-interrupted boot is observed and
asks whether the breaker has tripped.

A trip means: at least `max_restarts` restarts occurred within the last
`window_seconds`. When tripped, the caller should stop auto-resuming the
offending session (while still serving real inbound) instead of restarting
it again immediately.

Example::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
guard = RestartLoopGuard(max_restarts=3, window_seconds=60)
if guard.record(now=time.monotonic()):
    # too many restarts too fast — stop auto-resuming this session
    ...
```

## Constructor

<ParamField query="max_restarts" type="int" required={false} default="3">
  No description available.
</ParamField>

<ParamField query="window_seconds" type="float" required={false} default="60.0">
  No description available.
</ParamField>

## Methods

<CardGroup cols={2}>
  <Card title="record()" icon="function" href="../functions/RestartLoopGuard-record">
    Record a restart at `now` and return whether the breaker tripped.
  </Card>

  <Card title="tripped()" icon="function" href="../functions/RestartLoopGuard-tripped">
    Return whether the breaker is currently tripped without recording.
  </Card>

  <Card title="reset()" icon="function" href="../functions/RestartLoopGuard-reset">
    Clear the recorded restart history (e.g. after a clean run).
  </Card>
</CardGroup>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L4398">
  `praisonaiagents/gateway/protocols.py` at line 4398
</Card>
