A swarm on a provable bus #

What is new: agents talk through signed, content-addressed messages. Every message names its sender (and only that sender's key can sign it), what it replies to and what it cites. A worker cannot mark its own work done: a claim exists only if the task's checker recomputes the answer from the evidence. When an agent turns out to be compromised, one revocation invalidates everything it signed, and impact lists everything that built on it.

Why it matters: in a multi-agent pipeline, the usual record is a chat log anyone could have written, and "done" means an agent said so. Here "who said what" is a signature, "done" is a recomputed check, and a bad agent can be cut out after the fact without losing the rest of the run.

Three agents, one task #

from tensorchain import agents, issuers, provenance
from tensorchain.sign import canonical
from tensorchain.workspace import Workspace

reg = issuers.Registry("keys")
ws = Workspace("swarm.sqlite", actor="agent:docs").__enter__()
bus = agents.Bus(ws, reg)
for a in ("planner", "worker", "critic"):
    bus.join(a)                                                   # each agent gets its own signing key

task = bus.send("planner", "worker", "task", canonical({"op": "sort", "input": [42, 7, 19, 3]}))
claim = bus.claim("worker", task, canonical([3, 7, 19, 42]))      # recomputed by the checker, then signed
said = bus.send("worker", "critic", "claim", canonical({"claim": claim}), reply_to=task, cites=[claim])
review = bus.send("critic", "planner", "review", canonical({"verdict": "accepted"}), reply_to=said, cites=[claim])

print("delivered:", [bus.deliver(bus.envelope(m)) for m in (task, said, review)])
print("task done:", bool(bus.done(task)))
assert [bus.deliver(bus.envelope(m), receiver="planner") for m in (task, said, review)] == ["accepted"] * 3
assert bus.done(task) == [claim]
Output (captured at build)
delivered: ['accepted', 'accepted', 'accepted']
task done: True

A worker that gets it wrong never produces a claim at all:

task2 = bus.send("planner", "worker", "task", canonical({"op": "sum", "input": [10, 20, 30]}))
try:
    bus.claim("worker", task2, canonical(70))
    outcome = "claimed"
except agents.BusError as e:
    outcome = e.code
print("a wrong answer:", outcome, " task done:", bool(bus.done(task2)))
assert outcome == "claims_fail" and bus.done(task2) == []
Output (captured at build)
a wrong answer: claims_fail  task done: False

Forged, impersonated, replayed #

body = {"format": agents.FORMAT, "from": "worker", "to": "planner", "kind": "claim", "seq": 99,
        "payload": ws.put(b"trust me, it is done"), "reply_to": None, "cites": []}
outsider = issuers.Registry("outsider-keys")
outsider.create("agent:worker")                                   # the same name, someone else's key
print("forged by an outsider:", bus.deliver(outsider.sign("agent:worker", agents.MSG_TYPE, canonical(body))))
print("signed by the critic as the worker:", bus.deliver(reg.sign("agent:critic", agents.MSG_TYPE, canonical(body))))
print("the review delivered again:", bus.deliver(bus.envelope(review), receiver="planner"))
assert bus.deliver(outsider.sign("agent:worker", agents.MSG_TYPE, canonical(body))) == "signature_invalid"
assert bus.deliver(reg.sign("agent:critic", agents.MSG_TYPE, canonical(body))) == "signature_invalid"
assert bus.deliver(bus.envelope(review), receiver="planner") == "replay"
Output (captured at build)
forged by an outsider: signature_invalid
signed by the critic as the worker: signature_invalid
the review delivered again: replay

The worker was compromised #

bus.revoke_agent("worker")
print("worker's messages:", sorted({bus.status(r) for s, _, r in bus.messages("worker")}))
print("its claim:", provenance.verify_attestation(ws, reg, claim)["status"])
print("built on the claim:", len(bus.impact(claim)), "messages to re-check")
print("planner's task still:", bus.status(task), " critic's review signature still:", bus.status(review))
assert {bus.status(r) for s, _, r in bus.messages("worker")} == {"invalid"}
assert review in bus.impact(claim) and task not in bus.impact(claim)
assert bus.status(task) == "valid"
ws.__exit__(None, None, None)
Output (captured at build)
worker's messages: ['invalid']
its claim: invalid
built on the claim: 2 messages to re-check
planner's task still: valid  critic's review signature still: valid

The planner's task and the critic's own signatures stand; what the impact lists is exactly what to re-check because it relied on the worker. Nothing was deleted: the record of the compromise is itself signed.