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

# Turn Lock Config • AI Agent SDK

> TurnLockConfig: Configuration for cluster-wide per-turn serialisation (Issue #3643).

# TurnLockConfig

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

AI Agent

Configuration for cluster-wide per-turn serialisation (Issue #3643).

Selects the backend for the gateway's per-turn lock — the guarantee that
only one turn runs against a given resolved session at a time. The default
`"local"` backend reproduces today's in-process `asyncio.Lock` /
`LockMap` behaviour exactly (zero cost, no new dependency), so
single-replica deployments are byte-for-byte unchanged. Selecting
`"redis"` extends serialisation across every replica so a
horizontally-scaled gateway (`replicas &gt; 1`) no longer runs concurrent
turns on one session — the concrete distributed lock lives in the
wrapper/bot package and reuses the existing `RedisConfig` connection and
the scheduler's proven owner+TTL lease pattern.

This maps onto the pure core
:class:`~praisonaiagents.gateway.protocols.TurnLockProtocol`.

Attributes:
backend: `"local"` (default, in-process `asyncio.Lock`) or
`"redis"` (distributed lease, cluster-wide serialisation).
ttl: Lease time-to-live in seconds for a distributed backend. Bounds
how long a crashed holder's lease survives before it is reclaimable,
so a dead replica cannot wedge a healthy session (fail-open /
self-healing, as the scheduler already does). Inert for `"local"`.
url: Optional Redis URL for the `"redis"` backend. When omitted the
distributed lock reuses the gateway's configured `RedisConfig`.

## Properties

**backend** `str`

No description available.

**ttl** `float`

No description available.

**url** `Optional[str]`

No description available.

## Methods

> [card] [enabled()](https://praison.ai/docs/sdk/reference/praisonaiagents/functions/TurnLockConfig-enabled.md)
>
> Whether a distributed (cross-replica) turn lock is selected.

> [accordion] Internal & Generic Methods
>
> * **from\_dict**: Create from a parsed `gateway.turn_lock` mapping (tolerant of None).
> * **to\_dict**: Convert to dictionary (hides sensitive URL).

## Source

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

***

## Related Documentation

> [card] [Configuration Overview](https://praison.ai/docs/docs/configuration/index)

> [card] [Agent Config](https://praison.ai/docs/docs/configuration/agent-config)


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