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

# drain • AI Agent SDK

> drain: Process pending messages.

# drain

<div className="flex items-center gap-2">
  <Badge color="blue">Async</Badge>
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**OutboundDeliveryProtocol**](../classes/OutboundDeliveryProtocol) class in the [**protocols**](../modules/protocols) module.

Process pending messages.

Called on startup to retry unsent messages. Messages are processed
oldest-first to maintain order.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async def drain(sender: Callable[[str, Dict[str, Any]], Awaitable[bool]], limit: Optional[int]) -> tuple[int, int]
```

## Parameters

<ParamField query="sender" type="Callable" required={true}>
  Async function that attempts delivery. Should return True on success, False to retry later.
</ParamField>

<ParamField query="limit" type="Optional[int]" required={false}>
  Optional max messages to process
</ParamField>

### Returns

<ResponseField name="Returns" type="tuple[int, int]">
  Tuple of (succeeded, failed) counts
</ResponseField>

## Source

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