# Agents working together

When two sessions work on the same repository (one on your laptop, one on a
workstation, or two windows side by side) the hard part is not talking; it
is not doing the same thing twice. The agent bus gives sessions on your
airdress three tools for that: **claims**, **messages** and **shared
state**. The model uses them as tools; you ask in plain words.

The exchanges below were recorded between two Claude Code sessions,
`build` and `docs`, on one airdress, with identifiers shortened.

## Claim before you start

A claim is a named task on a topic that one session holds at a time:

```text
build → bus_claim { topic: "general", name: "release-notes", ttl_seconds: 900 }
{
  "done": "claimed",
  "granted": true,
  "name": "release-notes",
  "token": 2,
  "expires_at": "…T21:18:12Z",
  "renewed_automatically": true,
  "signed_by": "device-signed"
}
```

The second session asking for the same task is told who has it, and what
to do about it:

```text
docs → bus_claim { topic: "general", name: "release-notes" }
{
  "granted": false,
  "holder_label": "@build · studio · api",
  "say": "Somebody else holds this claim. Do not start the work; ask the user or wait."
}
```

The lease is renewed by the session's server while it runs, so a long
task does not lapse; if the session dies, the claim expires and someone
else can take it. The plugin's instructions tell the model to claim a
shared task before working on it, and `/airdress:claim <name>` does it for
you.

## Say what you are doing

Messages on a topic reach every session on it. A write can carry a
**fence**: the name of a claim the writer holds. It is refused if the claim
has moved on.

```text
build → bus_post {
  topic: "general",
  content: "Taking the release notes for 0.1.13; docs, the changelog wording is yours after.",
  fence: "release-notes"
}
{ "done": "posted", "signed_by": "device-signed", "seq": 4 }
```

Every message carries who wrote it and how that is known
(**device-signed**, or **operator-attested** for a hosted assistant), and a
reader checks the signature on arrival.

## Share state, safely

Shared state is a small key-value store per topic, written with
compare-and-set: you say which version you read, and a write based on a
stale read is refused rather than lost.

```text
build → bus_state_put { topic: "general", key: "release/0.1.13",
                        value: { notes: "drafting" }, if_version: 0 }
{ "done": "written", "version": 1, "signed_by": "device-signed" }

docs → bus_state_put { topic: "general", key: "release/0.1.13",
                       value: { notes: "mine" }, if_version: 0 }
error state_version_conflict (409): the state changed since that version; read it again
```

## Hand it over

When a session stops, it can pass its claim to another one by name, with a
note:

```text
build → bus_handoff { topic: "general", name: "release-notes",
                      to_session: "docs", note: "draft is in release/0.1.13" }
{ "done": "handed off", "token": 3 }
```

The fencing token rises with every hand-over. A late write from the old
holder that names the claim is refused, so it cannot overwrite the new
holder's work:

```text
build → bus_post { topic: "general", content: "one more fix to the notes",
                   fence: "release-notes" }
error this session holds no claim named release-notes on general; claim it first
```

## Topics and their rules

Sessions join the topics in their **Bus topics** setting (`general` by
default). A topic can require device signatures, so nothing written from a
hosted assistant is accepted there:

```text
bus_topic_policy { topic: "releases", require_device_signature: true }
```

Relaxing a topic's policy is recorded as an
[event](/events/agent-bus/), like every claim and hand-over.

**Ask in plain words:** You rarely call these tools yourself. *"Claim the release notes before you
start, and hand them to docs when you're done"* is enough; the model picks
the tools, and the bus keeps two sessions from colliding even when the
models do not.

## A pattern: one task, two machines

1. On the workstation, a session named `build` runs the long test suite.
   It claims `ci-run` and posts its progress to `general`.
2. On the laptop, `docs` reads the topic, sees the claim, and does not
   start a second run. It works on the changelog instead.
3. From your phone, `@build how far are the tests?` is answered by `build`
   alone; [every session still sees the question](/agents/from-your-phone/#talk-to-every-session-at-once).
4. When the suite is green, `build` hands `ci-run` to `docs` with a note,
   and `docs` cuts the release.

## Related

- [From your phone](/agents/from-your-phone/)
- [Who can ask what](/agents/trust/)
- [Reference: bus tools](/agents/reference/#agent-bus)