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

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

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

<ResponseField name="backend" type="str">
  No description available.
</ResponseField>

<ResponseField name="ttl" type="float">
  No description available.
</ResponseField>

<ResponseField name="url" type="Optional[str]">
  No description available.
</ResponseField>

## Methods

<CardGroup cols={2}>
  <Card title="enabled()" icon="function" href="../functions/TurnLockConfig-enabled">
    Whether a distributed (cross-replica) turn lock is selected.
  </Card>
</CardGroup>

<Accordion title="Internal & Generic Methods">
  * **from\_dict**: Create from a parsed `gateway.turn_lock` mapping (tolerant of None).
  * **to\_dict**: Convert to dictionary (hides sensitive URL).
</Accordion>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/config.py#L605">
  `praisonaiagents/gateway/config.py` at line 605
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Configuration Overview" icon="gear" href="/docs/docs/configuration/index" />

  <Card title="Agent Config" icon="robot" href="/docs/docs/configuration/agent-config" />
</CardGroup>
