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

# Liveness Policy • AI Agent SDK

> LivenessPolicy: Config-driven, pure liveness policy for half-open connection reaping.

# LivenessPolicy

> Defined in the [**protocols**](https://praison.ai/docs/sdk/reference/praisonaiagents/modules/protocols.md) module.

AI Agent

Config-driven, pure liveness policy for half-open connection reaping.

The default referenced by `gateway.liveness` blocks in `gateway.yaml`
and the `WebSocketGateway(..., liveness_policy=...)` Python surface. It is
intentionally minimal and dependency-free so the decision lives in core and
is provable in isolation; the wrapper owns the side effects (emit the
`PING` heartbeat, close the socket, force the client reconnect).

A connection is reaped once its `last_activity` is older than
`interval_ms × missed_beats_before_reap` — i.e. it has silently missed
that many heartbeat intervals. Any activity (an inbound frame, an inbound
`PONG`, or the peer's own `PING`) refreshes `last_activity` and keeps
the connection alive. The reference client typically force-reconnects after
`~2×` the interval of silence, so it heals before the server reaps it.

The window derivation is shared with the client watchdog via
:meth:`reap_deadline` / :attr:`interval_seconds` so both sides agree on the
same arithmetic from one advertised `interval_ms`.

`interval_ms` of `0` disables liveness reaping entirely (today's
behaviour: `last_activity` is stamped but never acted upon), so the
feature is fully backward-compatible and opt-in.

Example::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
LivenessPolicy(interval_ms=30_000, missed_beats_before_reap=2)
```

## Properties

**interval\_ms** `int`

No description available.

**missed\_beats\_before\_reap** `int`

No description available.

## Methods

> [card] [enabled()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/LivenessPolicy-enabled.md)
>
> Whether liveness reaping is active (a positive interval is set).

> [card] [interval\_seconds()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/LivenessPolicy-interval_seconds.md)
>
> The heartbeat interval expressed in seconds.

> [card] [reap\_deadline()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/LivenessPolicy-reap_deadline.md)
>
> Return the absolute time after which the connection is stale.

> [card] [evaluate()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/LivenessPolicy-evaluate.md)
>
> Return :attr:`LivenessDecision.REAP` iff the connection is stale.

## Source

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


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