> ## 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**](https://praison.ai/docs/sdk/reference/praisonaiagents/modules/protocols.md) module.

AI Agent

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

**max\_restarts** `int` (default: 3)

No description available.

**window\_seconds** `float` (default: 60.0)

No description available.

## Methods

> [card] [record()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/RestartLoopGuard-record.md)
>
> Record a restart at `now` and return whether the breaker tripped.

> [card] [tripped()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/RestartLoopGuard-tripped.md)
>
> Return whether the breaker is currently tripped without recording.

> [card] [reset()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/RestartLoopGuard-reset.md)
>
> Clear the recorded restart history (e.g. after a clean run).

## Source

> [card] [View on GitHub](https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L6011)
>
> `praisonaiagents/gateway/protocols.py` at line 6011


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