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

# Outbound Delivery Protocol • AI Agent SDK

> OutboundDeliveryProtocol: Protocol for durable outbound message delivery.

# OutboundDeliveryProtocol

> Defined in the [**protocols**](../modules/protocols) module.

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

Protocol for durable outbound message delivery.

Ensures messages sent to external channels (Telegram, Slack, Discord, etc.)
are persisted before sending and can be retried on failure. This provides
crash-safe at-least-once delivery for channel replies.

Example usage (implementation in praisonai\_bot.gateway):
from praisonai.bots import OutboundQueue

outbox = OutboundQueue(path="\~/.praisonai/state/outbox.sqlite")

# Enqueue before sending

key = await outbox.enqueue(
idempotency\_key="msg-123",
target\_channel="telegram:12345",
payload=\{"text": "Hello", "metadata": \{...}}
)

# Attempt delivery

success = await deliver\_with\_retry(adapter, channel\_id, payload)

# Mark as sent only if successful

if success:
await outbox.mark\_sent(key)

# On restart, drain pending messages

await outbox.drain(delivery\_handler)

## Methods

<CardGroup cols={2}>
  <Card title="enqueue()" icon="function" href="../functions/OutboundDeliveryProtocol-enqueue">
    Persist an outbound message for delivery.
  </Card>

  <Card title="mark_sent()" icon="function" href="../functions/OutboundDeliveryProtocol-mark_sent">
    Mark a message as successfully sent.
  </Card>

  <Card title="mark_failed()" icon="function" href="../functions/OutboundDeliveryProtocol-mark_failed">
    Mark a message as failed.
  </Card>

  <Card title="drain()" icon="function" href="../functions/OutboundDeliveryProtocol-drain">
    Process pending messages.
  </Card>

  <Card title="pending_count()" icon="function" href="../functions/OutboundDeliveryProtocol-pending_count">
    Get count of pending messages awaiting delivery.
  </Card>

  <Card title="size()" icon="function" href="../functions/OutboundDeliveryProtocol-size">
    Get total number of messages in queue.
  </Card>

  <Card title="purge_old()" icon="function" href="../functions/OutboundDeliveryProtocol-purge_old">
    Remove old sent messages.
  </Card>
</CardGroup>

## Source

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