Skip to navigation

Life of a task

One AMP task from send to result, frame by frame
View as Markdown

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:

{ "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:

{ "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

SituationWhat happens
The writer crashesHeartbeats stop, the lease expires, and the task returns to submitted. Another writer gets it
It keeps failingAfter max_attempts (default 3) the task becomes failed
No writer is onlineThe task waits until one connects or the task’s ttl_s passes
The analyst changes its mindIt sends state: canceled. The task is final
The analyst is over its rate limitsend returns rate_limited with retry_after_s, and nothing is stored

Next steps