> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paddockai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sending messages

> Let agents post to Slack threads, email, or your own endpoint with the send tool: keys, the allow list, reply routing, and the durable outbox.

Every agent has paddock's built-in MCP server, `paddock`, with one tool, `send`. An agent calls it to post a message somewhere outside its session: a Slack thread, an email address, your own endpoint. The message goes through a [connector](https://docs.paddockai.dev/guides/connectors.md)'s outbound side, whose deliver function holds the destination's credential, so the sandbox never sees it.

```mermaid theme={null}
sequenceDiagram
  participant Agent as Agent (in its sandbox)
  participant Outbox as paddock outbox
  participant Fn as Deliver function
  participant Slack
  Agent->>Outbox: send { key: "slack-acme:C0123ABCD", text }
  Outbox-->>Agent: { id: obx_..., status: "queued" }
  Outbox->>Fn: deliver(msg, ctx)
  Fn->>Slack: chat.postMessage
  Fn-->>Outbox: { ok: true, externalId }
```

```text theme={null}
send(key?, text, attachments?)
  key:          "<connector>:<address>", such as "slack-acme:C0123ABCD"; omit it to answer
                where the session's conversation came from
  text:         the message, in Markdown, at most 100 KB
  attachments:  [{ path, name? }]: up to 10 files under /home/user, 25 MB each, 50 MB together
  returns { id, key, status: "queued" } once the message is committed; it is delivered after
```

The tool answers as soon as the message is committed to the **outbox**; delivery happens after, retried as often as it takes, always with the same message ID. A refused send is a tool error whose text starts with its code, so the agent can correct the call in the same turn:

| Code | When |
| - | - |
| `invalid_key` | The key is malformed or over 600 bytes |
| `no_reply_key` | No key was given and the session has no reply key |
| `unknown_connector` | No connector of the project has the key's name |
| `no_outbound` | The connector has no outbound side, or no deliver function |
| `not_allowed` | The key is not the session's reply key and matches no pattern of the agent's allow list |
| `invalid_text` | The text is empty or over its limit |
| `invalid_attachment` | A path is missing, not a regular file, outside `/home/user`, or over a limit |
| `unavailable` | The message could not be confirmed; it may still be queued, so the agent checks before sending again |

## Set up the outbound side

Create a connector with an outbound side, set its deliver function, here the `slack` preset, and the secrets it reads:

```go Go theme={null}
connector, err := client.Connectors.Create(ctx, paddock.ConnectorCreate{
	Name:     "slack-acme",
	Inbound:  &paddock.InboundCreate{},
	Outbound: &paddock.OutboundCreate{RateLimit: &paddock.RateLimit{PerMinute: 50}},
	Secret:   os.Getenv("SLACK_SIGNING_SECRET"),
})
if err != nil {
	return err
}
if _, err := connector.Secret.Rotate(ctx, paddock.SecretRotate{Name: "bot_token", Secret: os.Getenv("SLACK_BOT_TOKEN")}); err != nil {
	return err
}
for _, side := range []string{paddock.SideInbound, paddock.SideOutbound} {
	params := map[string]string{}
	if side == paddock.SideInbound {
		params["agent"] = agent.ID
	}
	if _, err := connector.Functions.Set(ctx, side, paddock.FunctionSet{Runtime: paddock.RuntimeNodeJS, Preset: "slack", Params: params}); err != nil {
		return err
	}
}
```

```python Python theme={null}
import os

connector = client.connectors.create(
    {
        "name": "slack-acme",
        "inbound": {},
        "outbound": {"rateLimit": {"perMinute": 50}},
        "secret": os.environ["SLACK_SIGNING_SECRET"],
    }
)
connector.secret.rotate(name="bot_token", secret=os.environ["SLACK_BOT_TOKEN"])
connector.functions.set("inbound", runtime="nodejs24.x", preset="slack", params={"agent": agent.id})
connector.functions.set("outbound", runtime="nodejs24.x", preset="slack")
```

```ts TypeScript theme={null}
const connector = await paddock.connectors.create({
  name: "slack-acme",
  inbound: {},
  outbound: { rateLimit: { perMinute: 50 } },
  secret: process.env.SLACK_SIGNING_SECRET,
});
await connector.secret.rotate({ name: "bot_token", secret: process.env.SLACK_BOT_TOKEN });
await connector.functions.set("inbound", { runtime: "nodejs24.x", preset: "slack", params: { agent: agent.id } });
await connector.functions.set("outbound", { runtime: "nodejs24.x", preset: "slack" });
```

The outbound presets are `slack` (a channel ID, or `channel/thread_ts` for a thread, as the address), `webhook` (a signed POST to the param `url`, with the address in the body), and `email-ses` (an email address). Write your own with the [deliver contract](https://docs.paddockai.dev/guides/connector-functions.md#deliver-contract).

## Keys and the allow list

A key is the connector's name, `:`, and an address, such as `slack-acme:C0123ABCD/1763600000.123456`. paddock splits it at the first `:` and never reads the address; the deliver function decides what it means. Keys are compared byte for byte.

An agent may send to its session's **reply key** and to the keys its allow list permits. A template lists them as patterns in `spec.outbox.allow`, where `*` matches any run of characters, `:` and `/` included:

```yaml theme={null}
spec:
  outbox:
    allow:
      - "slack-acme:*"                  # any channel or thread of slack-acme
      - "mail:oncall@acme.com"          # one address
```

An agent may replace its template's list with its own, at most 50 patterns:

```go Go theme={null}
setting, err := agent.Outbox.Set(ctx, paddock.OutboxSpec{Allow: []string{"slack-acme:C0123ABCD/*"}})
if err != nil {
	return err
}
fmt.Println(setting.Source, setting.Value.Allow) // agent [slack-acme:C0123ABCD/*]
```

```python Python theme={null}
setting = agent.outbox.set(allow=["slack-acme:C0123ABCD/*"])
print(setting.source, setting.value.allow)  # agent ['slack-acme:C0123ABCD/*']
```

```ts TypeScript theme={null}
const setting = await agent.outbox.set({ allow: ["slack-acme:C0123ABCD/*"] });
console.log(setting.source, setting.value.allow); // agent [ 'slack-acme:C0123ABCD/*' ]
```

`agent.outbox.delete()` restores the template's list. Without a list, an agent sends only to its sessions' reply keys. Each send is checked against the list as it is then; a message already queued is delivered even if the list changes.

## Reply routing

A session has at most one reply key: where its conversation takes place. `send` without a key goes there, and the reply key needs no pattern, since only your code sets it, never the agent.

* An inbound route's `replyKey` becomes the session's reply key when the route is delivered; the newest delivered route wins. The `slack` preset sets the thread of each mention, so the agent answers in the thread it was asked in.
* `agent.sessions.create` takes a `replyKey` for a session your code starts:

```go Go theme={null}
s, err := agent.Sessions.Create(ctx, paddock.SessionCreate{ReplyKey: "slack-acme:C0123ABCD"})
if err != nil {
	return err
}
fmt.Println(*s.ReplyKey)
```

```python Python theme={null}
s = agent.sessions.create(reply_key="slack-acme:C0123ABCD")
print(s.reply_key)
```

```ts TypeScript theme={null}
const s = await agent.sessions.create({ replyKey: "slack-acme:C0123ABCD" });
console.log(s.replyKey);
```

A deliver function answers the `externalId` of what it posted. An inbound route with `replyTo` set to that ID reaches the session that posted it, so a reply to the agent's message lands in the conversation that wrote it, even when the agent started the thread on its own. With `matchOnly`, a route without such a session is recorded `unmatched` instead of starting a new one: the `slack` preset routes thread replies this way, so the agent hears replies only in threads it wrote in.

## The outbox

Every accepted send is an outbox message, with an `obx_...` ID:

| Status | Meaning |
| - | - |
| `queued` | Waiting for its turn, its connector's pace, or a retry; `waitingFor` names the earlier message of its key |
| `delivering` | An attempt is running |
| `delivered` | The deliver function answered ok, with `externalId` |
| `failed` | A permanent error, no attempts left, 24 hours queued, or its connector or session deleted; `error` says which |

```go Go theme={null}
for m, err := range client.Outbox.List(ctx, paddock.OutboxList{SessionID: session.ID, Status: "failed"}) {
	if err != nil {
		return err
	}
	fmt.Println(m.ID, m.Key, m.Error.Message)
	if _, err := client.Outbox.Retry(ctx, m.ID); err != nil {
		return err
	}
}
```

```python Python theme={null}
for m in client.outbox.list(session_id=session.id, status="failed"):
    print(m.id, m.key, m.error.message if m.error else None)
    client.outbox.retry(m.id)
```

```ts TypeScript theme={null}
for await (const m of paddock.outbox.list({ sessionId: session.id, status: "failed" })) {
  console.log(m.id, m.key, m.error?.message);
  await paddock.outbox.retry(m.id);
}
```

`outbox.list` filters by `connectorId`, `sessionId`, `key`, and `status`, newest first. `outbox.retry` queues a failed message again with the same ID and its place in its key's order.

What the outbox promises:

* **Durable.** A message is committed before the tool answers, and every attempt uses its ID, which a deliver function gives its destination as an idempotency key.
* **Order.** Messages of one key are delivered in the order they were sent; a later one never overtakes an earlier one.
* **Retries.** Up to 6 attempts, 10 seconds, 40 seconds, 160 seconds, about 11 minutes, and about 43 minutes apart, or later when the destination's `retryAfter` asks.
* **Pace.** A connector delivers at most `rateLimit.perMinute` messages a minute, and a `retryAfter` holds all of its keys until it ends, without using an attempt.
* **Credentials.** A permanent error with code `auth` sets the connector's `outbound.credentialError`, which the console shows; the next delivered message, after you rotate the secret, clears it.

## Events

Each step is an event in the session's log, which `events.list`, the stream, and the client SDK's `events` show; none starts a turn:

| Type | When | Payload `outbox` |
| - | - | - |
| `outbox.queued` | A send is committed, or `outbox.retry` queues a message again | `id`, `connectorId`, `key`, `turnId`, `text`, `attachments`, `retry` |
| `outbox.delivered` | An attempt answered ok | `id`, `externalId`, `attempts` |
| `outbox.failed` | A message failed, unless its session was deleted | `id`, `class`, `code`, `message`, `attempts` |

## Attachments

The daemon uploads each file the agent names to object storage before the message is committed, and each attempt gives the deliver function a download link valid one hour in `msg.attachments`. Files are kept 30 days, so a message retried after that is delivered without them.


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