> ## 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**](../modules/protocols) module.

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

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

<ResponseField name="interval_ms" type="int">
  No description available.
</ResponseField>

<ResponseField name="missed_beats_before_reap" type="int">
  No description available.
</ResponseField>

## Methods

<CardGroup cols={2}>
  <Card title="enabled()" icon="function" href="../functions/LivenessPolicy-enabled">
    Whether liveness reaping is active (a positive interval is set).
  </Card>

  <Card title="interval_seconds()" icon="function" href="../functions/LivenessPolicy-interval_seconds">
    The heartbeat interval expressed in seconds.
  </Card>

  <Card title="reap_deadline()" icon="function" href="../functions/LivenessPolicy-reap_deadline">
    Return the absolute time after which the connection is stale.
  </Card>

  <Card title="evaluate()" icon="function" href="../functions/LivenessPolicy-evaluate">
    Return :attr:`LivenessDecision.REAP` iff the connection is stale.
  </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#L5263">
  `praisonaiagents/gateway/protocols.py` at line 5263
</Card>
