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

# Concurrency Limit Policy • AI Agent SDK

> ConcurrencyLimitPolicy: Config-driven inbound admission policy for a bounded gateway.

# ConcurrencyLimitPolicy

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

AI Agent

Config-driven inbound admission policy for a bounded gateway.

The default referenced by `gateway.max_concurrent_runs` /
`gateway.queue_depth` / `gateway.overflow_policy` in `gateway.yaml`
and the `BotOS(..., max_concurrent_runs=...)` 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 (acquire a
semaphore slot, enqueue/dequeue, return a busy ack).

The decision is:

* `ADMIT` while `in_flight &lt; max_concurrent_runs`.
* At the ceiling, `QUEUE` while `queued &lt; queue_depth` and the
  `overflow_policy` permits waiting.
* Otherwise the `overflow_policy` decides the shed behaviour:
  * `"reject"` → :attr:`AdmissionDecision.REJECT` (busy ack).
  * `"queue"` → :attr:`AdmissionDecision.QUEUE` (block beyond the
    declared depth — for callers that prefer unbounded waiting to
    shedding; the wrapper still bounds the actual queue object).
  * `"shed_oldest"` → :attr:`AdmissionDecision.QUEUE`; the wrapper
    drops the oldest waiter to make room rather than rejecting the new
    arrival.

A `max_concurrent_runs` of `0` disables admission control entirely
(today's behaviour: every inbound turn is admitted immediately).

On a shared/multi-tenant gateway an optional `max_concurrent_runs_per_scope`
caps concurrency *per tenant/scope* within the global ceiling (Issue #5168):
a tenant that already holds its sub-limit is queued/shed against its own
slice even when a global slot is notionally free, so a noisy neighbour
cannot starve quiet tenants. A value of `0` (the default) disables the
per-scope sub-limit, preserving the byte-for-byte global-only behaviour.

Example::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
ConcurrencyLimitPolicy(max_concurrent_runs=32, queue_depth=128,
                       overflow_policy="reject",
                       max_concurrent_runs_per_scope=4)
```

## Constructor

**max\_concurrent\_runs** `int` (default: 0)

No description available.

**queue\_depth** `int` (default: 0)

No description available.

**overflow\_policy** `str` (default: 'reject')

No description available.

**max\_concurrent\_runs\_per\_scope** `int` (default: 0)

No description available.

## Methods

> [card] [enabled()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/ConcurrencyLimitPolicy-enabled.md)
>
> Whether admission control is active (a positive ceiling is set).

> [card] [decide()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/ConcurrencyLimitPolicy-decide.md)
>
> Instance method.

## Source

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


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