@m-cpy/pi-a2a-inbox0.5.1
A2A peer collaboration for pi — standard A2A v1.0 envelope + inbox extension, static URL peers, per-peer Bearer identity, session continuation
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-a2a-inbox
Agent-to-agent (A2A) peer collaboration for pi — static URL peers, per-peer Bearer identity, inbox semantics. Built on the standard A2A v1.0 envelope plus a private inbox extension. No mDNS, no shared-trust secret, no outbox.
@m-cpy/pi-a2a-inbox lets pi talk to named peers (e.g. reviewer, backend). Messages are organized per peer session; inbound always lands in the inbox as pending, and replying is an explicit action.
What It Does
- 📨 Send messages — start a conversation, ask a question, share a code snippet
- 💬 Explicit replies —
a2a_replyanswers an inbox message in the sender's session - 📥 Inbox four-state —
pending → consuming → done, plussuspendedfor stuck messages - 👥 Peers + sessions —
a2a_peerslists configured peers;a2a_sessionslists the sessions you've exchanged with a peer - 🔔 Honest wake — a nudge wakes the agent only on real delivery; at most 3 attempts per batch, then stop or suspend
This is a direct agent-to-agent channel, not human chat or a shared blackboard.
Architecture
Standard A2A v1.0 (JSON-RPC 2.0 over HTTP) envelope + a private inbox extension:
- Extension URI:
https://a2a-inbox.local/ext/a2a-inbox/v1, declared in the Agent Card withrequired: true. - A pure-standard A2A client that omits the extension metadata is rejected with
-32009(by design — the fallback surface is not opened).
static URL peers (no discovery daemon)
┌──────────────┐ HTTPS/HTTP ┌──────────────┐
│ pi │ JSON-RPC │ reviewer │
│ Agent Card │ ◄────────────► │ Agent Card │
│ POST /rpc │ SendMessage │ POST /rpc │
│ inbox (JSON) │ + ext meta │ inbox (JSON) │
└──────────────┘ └──────────────┘
- Discovery — none. Peers are configured statically by Agent Card URL (
peers[]). The card is fetched at startup to resolve the RPC endpoint. - Identity — per-peer Bearer token. Outbound uses the token the peer issued for you (the one that identifies you as you); inbound resolves the peer name by matching the token against each peer's
inboundToken(fallbackbearer). A self-reported name never participates in routing. - Single writer — the process that owns the listen port runs the inbox; other processes degrade to client-only and route inbox ops to the owner over RPC.
- Storage — one local JSON file (
.pi/a2a-messages.json): messages, dedup, nudges, counters, and a participation ledger (decoupled from message rows so trimming history never retracts disclosure).
Trust model
- The shared
workspaceSecretis only an anonymous entry (_shared); it does not produce a peer identity. - Real communication uses per-peer dedicated tokens. One credential must map to exactly one peer.
- B rule (I6): if one inbound credential maps to more than one peer, requests carrying it are always 401 + -32041 — not first-wins, not "log and accept". Enforced at save (reject), load (warn naming both peers), and runtime (401).
- Bind is LAN-oriented; for cross-internet use put agents behind a VPN.
Install
pi loads this as a package. From npm (published):
pi install npm:@m-cpy/pi-a2a-inbox
It also appears in the Pi package gallery. The package bundles the extension (./extensions) and a skill (./skills/pi-a2a-inbox). No native dependency, no mDNS daemon; host packages (@earendil-works/pi-coding-agent, typebox) are provided by pi.
Or install from the public monorepo source:
git clone https://github.com/Mcpy/a2a-inbox
pi install ./a2a-inbox/pi-a2a-inbox
(Or add the path to ~/.pi/agent/settings.json packages.)
Configure
Config is per-project: .pi/pi-a2a.json.
{
"workspace": "my-team",
"workspaceSecret": "anonymous-entry-pass",
"peerName": "pi",
"listenPort": 0,
"peers": [
{
"name": "reviewer",
"url": "http://peer-host:8080/.well-known/agent-card.json",
"bearer": "outbound-token-the-peer-issued-for-me",
"inboundToken": "inbound-token-the-peer-carries-when-calling-me"
}
]
}
| Field | Meaning |
|---|---|
workspace |
Workspace label |
workspaceSecret |
Anonymous entry secret (_shared, no peer identity); communication needs peers[] |
peerName |
This agent's name |
listenPort |
Local HTTP port (0 = OS-assigned) |
advertiseHost |
Optional outbound advertise host (multi-NIC/Docker/WSL) |
agentCardPath / rpcPath |
Card / RPC paths (defaults /.well-known/agent-card.json, /rpc) |
peers[] |
Static peers, one row per relationship: name, url (card), bearer (outbound), inboundToken (inbound, fallback bearer) |
inboundToken omitted = symmetric reuse of bearer (one dedicated pair may explicitly reuse one token; leakage is then bidirectional). Environment references supported: "bearer": "$PEER_TOKEN".
Slash commands
| Command | Description |
|---|---|
/a2a-status |
Engine status (config path, port, running sessions, peers) |
/a2a-restart |
Restart the engine (guards against busy sessions) |
/a2a-setup <secret> [name] |
Set engine basics (secret = anonymous entry) |
/a2a-setup peer <name> <cardUrl> <outToken> [inToken] |
Add/update a peer row (per-peer Bearer) |
/a2a-setup peers |
List peer rows (token tails, direction) |
/a2a-setup del-peer <name> |
Remove a peer row |
Tools (7)
| Tool | Description |
|---|---|
a2a_peers |
List configured peers + online status |
a2a_sessions |
List a peer's sessions (sessionId/title/status/pending); never guess a sessionId |
a2a_send |
Send. peer required; continue with sessionId, new session requires explicit newSession:true |
a2a_inbox_list |
This session's inbox overview (counts/sender/topic/mustReply), no bodies |
a2a_inbox_fetch |
Fetch body (→ consuming). mustReply:true must be answered with a2a_reply in the same turn |
a2a_reply |
Reply to an inbox message (recipient auto = original sender). New topics use a2a_send |
a2a_inbox_drop |
Destroy a suspended message (only on explicit user instruction) |
Routing rules (v3)
contextId= the peer's session id: empty → new; non-empty but unknown →-32040(never silently creates a session; the error does not echo the caller's id).metadata.senderSessionIdis required (full session id); reply routing depends on it.- Disclosure A+:
a2a_sessionslists only sessions exchanged with that peer, labeled by the latest topic the peer already knows; invisible sessions never echo their id.
Retention
| State | Age basis | Rule |
|---|---|---|
pending > 24h |
receivedAt |
→ suspended(expired) (reversible) |
suspended > 72h |
suspendedAt |
→ deleted (purged) |
done > 24h |
doneAt |
→ trimmed (trimmed) |
Suspended reasons: no-reply-3x / reply-failed-3x / session-gone / expired. Deletion event lines carry the messageId list (audit). Participation facts are stored independently, so trimming done rows never retracts the disclosure surface.
Error codes
| Code | Meaning |
|---|---|
-32040 |
Unknown session (never creates) |
-32041 |
Unauthorized (HTTP 401; includes ambiguous credential per B rule) |
-32042 |
Peer unreachable (connect failure / timeout) |
-32043 |
Same id, different body |
-32044 |
Box full (cap 1000) |
-32045 |
Message not pending (already consumed / suspended / done) |
-32046 |
Message is suspended (fetch it back before replying) |
-32047 |
Message already answered (use a2a_send to continue) |
-32048 |
Session archived on the peer (exists, takes no new messages) |
-32009 |
Extension not activated (URI mismatch / pure-standard client) |
-32602 |
Invalid params (body > 32768, missing senderSessionId, …) |
pi has no archive concept: it never emits archived and never answers -32048. It is a
consumer of that code — the client keeps it distinct from -32040 (retry with another id) and
-32042 (peer down, back off), because those three demand opposite reactions. m11 asserts all
codes stay unique and that -32048 is never claimed by another name.
Delivery semantics (delivered ≠ woke)
The wire receipt delivered:true means the message entered the inbox ("received"), per PROTOCOL-v3 §9.2 — it is constant on successful receive, independent of whether the agent was woken. Wake failure never makes it false; a receive failure throws an error code instead. This semantics is aligned across implementations.
Wake state is tracked separately (internal nudge budget: at most 3 real deliveries per batch). A future wakeState: yes|queued|no field may expose wake progress for reminders only — it must never trigger body re-send (that would turn "will wake later" into "not delivered" and cause duplicate delivery).
Observability
Counters: recv/dup/returned/wakeQueued/wakeFail/susp.*/lastInbound/lastClaim/lastWakeOk/rejects{noToken,unknownToken,ambiguousToken}/selfProbes/purged/trimmed. A periodic self-probe (120s) detects a deaf sidecar; a watchdog (60s) drives reminder cooldown and stall detection. Effective config is logged at startup with its source.
Tests
bash scripts/run-v3-tests.sh # m2 sessions / m10 inbox / m11 envelope / m13 single-writer / m14 wake honesty / m15 crash recovery
bash scripts/typecheck.sh
Docs
Protocol and design documents are maintained internally by the team and are not shipped with this package. The code (including its comments) is the only public contract here.