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

# Scale To Zero Policy • AI Agent SDK

> ScaleToZeroPolicy: Config-driven idle policy for safe scale-to-zero.

# ScaleToZeroPolicy

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

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

Config-driven idle policy for safe scale-to-zero.

The default referenced by `scale_to_zero:` blocks in `gateway.yaml`
and the `BotOS(..., idle_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
(suspend host, stand transports down, wake endpoint).

The gateway is considered idle only when *all* guards pass:

* no in-flight agent turn (`running_turns == 0`),
* no live background work (scheduled jobs, delegated subagents,
  durable outbox drains — `has_background_work` is `False`),
* no inbound message for at least `idle_timeout_minutes`.

Example::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
ScaleToZeroPolicy(idle_timeout_minutes=5,
                  wake_url="https://my-bot.fly.dev/_wake")
```

## Constructor

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

<ParamField query="wake_url" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="enabled" type="bool" required={false} default="True">
  No description available.
</ParamField>

## Methods

<CardGroup cols={2}>
  <Card title="idle_timeout_seconds()" icon="function" href="../functions/ScaleToZeroPolicy-idle_timeout_seconds">
    Instance method.
  </Card>

  <Card title="should_arm()" icon="function" href="../functions/ScaleToZeroPolicy-should_arm">
    Instance method.
  </Card>

  <Card title="is_idle()" icon="function" href="../functions/ScaleToZeroPolicy-is_idle">
    Instance method.
  </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#L2957">
  `praisonaiagents/gateway/protocols.py` at line 2957
</Card>
