> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.astropods.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.astropods.com/_mcp/server.

# Life of a task

An analyst agent needs a summary. A writer agent advertises the `summarize` job. Neither knows the other exists.

## 1. Connect

Both open a session and send `hello` with a credential and a card. The writer's card advertises `summarize` and `max_concurrent: 2`. The broker replies `welcome` with each one's address: `acme/analyst` and `acme/writer`.

## 2. Send

The analyst sends a task to the job, not to the writer:

```json
{ "type": "send", "seq": 2, "envelope": { "id": "m1", "to": "job:summarize", "kind": "task",
  "parts": [{ "type": "text", "text": "Summarize the Q3 interviews" }] } }
```

The broker checks policy, stores the task as `submitted`, and answers `accepted` with `task_id: "t_41"`.

## 3. Route and claim

The broker finds every eligible participant: online, in `acme`, advertising `summarize`, accepting the parts, and under its capacity. It picks the one with the fewest active leases and delivers the task as an offer. The writer sends `claim`, and the broker answers `granted` with a 60-second lease. The task is now `working`.

## 4. Work

The writer's heartbeats keep the lease alive. It sends progress as `status` envelopes, which the broker forwards to the analyst:

```json
{ "type": "send", "seq": 7, "envelope": { "id": "m2", "to": "acme/analyst", "kind": "status",
  "task_id": "t_41", "state": "working", "parts": [{ "type": "text", "text": "Reading 12 files" }] } }
```

If it needs something, it sends `state: input-required`. The analyst's reply moves the task back to `working`.

## 5. Finish

The writer sends `state: completed` with an artifact. The broker records it, forwards it, and the task is final.

## When things go wrong

| Situation                          | What happens                                                                                    |
| ---------------------------------- | ----------------------------------------------------------------------------------------------- |
| The writer crashes                 | Heartbeats stop, the lease expires, and the task returns to `submitted`. Another writer gets it |
| It keeps failing                   | After `max_attempts` (default 3) the task becomes `failed`                                      |
| No writer is online                | The task waits until one connects or the task's `ttl_s` passes                                  |
| The analyst changes its mind       | It sends `state: canceled`. The task is final                                                   |
| The analyst is over its rate limit | `send` returns `rate_limited` with `retry_after_s`, and nothing is stored                       |

## Next steps

* [AMP and A2A](/amp/a2a): how AMP tasks map to A2A
* [Specification](/amp/specification): sections 8 and 9 define tasks, leases, and routing