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

# Ensure Run Lock • AI Agent SDK

> ensure_run_lock: Lazily mint obj._run_lock under a shared module guard.

# ensure\_run\_lock

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**\_run\_lock**](../modules/_run_lock) module.

Lazily mint `obj._run_lock` under a shared module guard.

`getattr(obj, "_run_lock", None)` works for both the dataclass-field case
(Workflow) and the plain-attribute case (AgentTeam), so the behaviour is
identical to the per-module implementations it replaces.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def ensure_run_lock(obj) -> Any
```

## Parameters

<ParamField query="obj" type="Any" required={true}>
  The orchestration instance (AgentTeam or Workflow) whose per-instance `_run_lock` should be returned, creating it on first access.
</ParamField>

### Returns

<ResponseField name="Returns" type="Any">
  The instance's `_run_lock` — the same object for every caller under a concurrent first-access race.
</ResponseField>

## Uses

* `getattr`
* `threading.Lock`

## Source

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

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Concurrency" icon="arrows-split-up-and-left" href="/docs/docs/features/concurrency" />

  <Card title="Thread Safety" icon="lock" href="/docs/docs/features/thread-safety" />

  <Card title="AgentTeam Batch" icon="layer-group" href="/docs/docs/features/agentteam-batch" />

  <Card title="Workflows Feature" icon="diagram-project" href="/docs/docs/features/workflows" />
</CardGroup>


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