From 1257e08e788e03609fe2803662929dd21856ba9f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 22 Sep 2026 13:45:06 +1000 Subject: [PATCH] docs(prds): cement A2A as the agent-to-agent protocol Sam's decision, recorded as requirements rather than options. A2A carries agent-to-agent work: discovery of what a remote agent offers, delegation of a unit of work, progress on it, and the artifacts it produces. MCP stays the tool layer -- the two are complementary, and internal/tools/provider already registers MCP providers as optional capabilities. A2A rides archie's existing transports, which the protocol permits: its canonical data model is Protocol Buffer messages and it defines a gRPC binding, so archie speaks it over the gRPC and NATS it already runs. The boundaries are requirements. internal/domain/messaging stays the human and channel layer, because a Conversation is a ChannelID and a ThreadID and its participants are people. internal/agentexec stays the daemon-to-worker execution protocol, whose Request, Result, gate and budget policy A2A never carries. A2A is an edge protocol that composes with both. The load-bearing decision, and the one that constrains everything downstream: archie's work lifecycle is MAPPED to A2A's, not expressed in it. An A2A task is a view over archie's own task, and archie's status stays the record of truth. Three gaps make the mapping partial, and each is a fact A2A's states cannot hold: A2A's terminal states describe what the agent did, while archie's merged and rejected describe what a forge did afterwards; pr_open hands work to a human reviewer, while A2A's input-required means the CLIENT must send more input; and declined, parked and dead are outcomes of archie's own policy. Adopting A2A's state names as the persisted task status is rejected outright -- it would migrate the task store and drop the forge outcomes that tell a caller whether the work was accepted. An A2A agent is an Identity: the actor archie persists, versions and scopes credentials to. A persona is prompt text with no endpoint; an agent container is task-scoped and ephemeral; the daemon is the process that serves the identity. The Gateway serves the card for the identity it is configured as, over the gRPC binding's Get Agent Card operation, and the card is derived -- skills from the catalog, identity from configuration, capabilities from what the process already advertises -- never hand-written, and carries no secret. archie is a server first, because the work a peer would delegate exists only inside archie. An inbound call is authenticated at the transport by the bearer-token interceptor the Gateway already applies: A2A carries no identity in its payload, so the transport credential is the identity. Authorization is per skill, which is A2A's own model. Task-scoped grants are not A2A credentials -- reusing one would let a peer act with a worker's authority -- and the dashboard's authentication gates an operator interface, not an agent endpoint. The new PRD is a development-audience page, so it regenerates the development artifact rather than the public one: dev-docs.json goes to 68 pages and docs.json is unchanged. Verified: task check exit 0, including docs:prds, and both docsite checks. --- docs/data/generated/dev-docs.json | 10 ++ docs/prds/agent2agent-protocol.md | 164 ++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 docs/prds/agent2agent-protocol.md diff --git a/docs/data/generated/dev-docs.json b/docs/data/generated/dev-docs.json index 9e688c51e..1ac92e5d8 100644 --- a/docs/data/generated/dev-docs.json +++ b/docs/data/generated/dev-docs.json @@ -114,6 +114,12 @@ "section": "PRDs", "body": "# Adversarial self-review stage -- decision\n\n**Status:** Finalised\n**Authority:** `docs/architecture/adversarial-review.md` describes the stage and is authoritative. This PRD remains the design-decision record.\n**Date:** 2026-08-22\n**Beads issue:** `archie-core-h019.1`, blocks `h019.2/.3/.4/.5`\n\n\u003e **Section 1 is superseded by the decision below.**\n\u003e The original execution mechanism assumed daemon-owned in-process execution\n\u003e and a daemon-side second `Pool.Acquire`; `archie-core-q15y` removed both\n\u003e call sites, leaving one open question: how a fresh reviewer receives an\n\u003e isolated snapshot from inside the task-scoped worker, without a host\n\u003e executor or a nested container lifecycle. Section 1 below now answers it\n\u003e with `agent.Subagent`. Sections 2-5 were never invalidated and still hold;\n\u003e section 3's contract shipped as `archie-core-h019.2`.\n\nAnswers the five questions in `h019.1`'s description against the actual\nimplement workflow, not designed from scratch: the gate pattern, the\ncontainer pool, and the workflow engine's `Outcome` mechanism already answer\nmost of this.\n\n## 1. Where it runs: `agent.Subagent`, inside the task worker\n\nThe implement workflow's stage list\n(`internal/domain/workflow/implement.go`) already has the right slot:\nafter `StageDiffCap()`, before `StageOpenPR()` -- gates\nhave passed, the diff is final, and nothing has told the forge about this\nchange yet.\n\n**The reviewer is an `agent.Subagent` run, not a second container.** ai-sdk\n`v0.1.22` (already the pinned version) added `agent/subagent.go`: a nested,\nsynchronous `core.GenerateText` call in the same process, with its own model,\nsystem prompt, toolset and step budget. That is what makes this feature\nbuildable at all after `q15y` -- the reviewer runs inside the task-scoped\n`archie-agent` worker that is already executing the workflow, so there is no\nhost executor, no second `Pool.Acquire`, and no nested container lifecycle.\n\n**Two isolations are needed, and Subagent only provides one of them.**\n\n*Conversation isolation is structural, and free.* `Subagent.Run`\n(`agent/subagent.go`) calls `GenerateText` with `Prompt` set and\n`Messages` never populated. The implementer's history has no code path into\nthe nested run; only the prompt string crosses, and only text comes back.\nThis is the literal form of \"environmental enforcement over prompt rules\":\nthe reviewer is not told to ignore the implementer's reasoning, because\nnothing hands it any. `h019.3`'s required test asserts this as a construction\nfact.\n\n*Workspace isolation is still ours to build.* A sub-agent shares the parent's\nprocess, working directory and credentials. So the `.git`-free snapshot from\nthe original decision survives unchanged and is load-bearing: export the\nreviewed commit (`git archive \u003ccommit\u003e | tar -x`) into a fresh scratch\ndirectory beside, not inside, the task worktree, and write `diff.patch` (the\ndiff already computed for `StageYaegiGate`'s `Trees.Diff()`) and `issue.md`\n(the originating issue's title and body, nothing else) alongside it. Stripping\n`.git` is what makes commit messages, branch name and reflog -- the actual\nchannel a multi-commit implementer's reasoning leaks through -- structurally\nunreachable rather than merely undisclosed.\n\n`Subagent.Tools` therefore takes a **distinct read-only toolset rooted at the\nsnapshot**. Never the worker's own toolset: it carries the `worktreerpc`\npublication grant, so a reviewer holding it could push the branch it exists to\nblock.\n\n**Call `Run()`, not `Tool()`.** `Tool()` would register delegation as a tool\nthe *implementer's* model may choose to invoke -- self-certification by the\nimplementer, which is the exact failure this feature exists to prevent. The\nstage calls `Run()` unconditionally. That also sidesteps both of `Tool()`'s\ndocumented footguns: the parent's two-step minimum and the recursion risk of\npassing a toolset back to itself.\n\n**Findings return through a closure, not the return value.** `Run` yields only\nfinal text, so section 3's structured contract cannot ride the return. Because\nthe sub-agent is in-process, the capture tool's Go implementation appends\ndirectly to a `[]workflow.ReviewFinding` the stage owns. This preserves the\n\"cannot end its turn without calling a typed tool\" property, and it defeats\n`Subagent`'s documented \"no partial results on failure\" limitation: findings\nalready captured survive an error return, so **the stage reads the captured\nslice even when `Run` returns an error**. A reviewer that logged three defects\nand then hit its step limit still yields those three.\n\n## 2. What it's given, and what it must never be given\n\n**Given:** the clean file-content snapshot (so the reviewer can read whole\nfiles -- follow an import, check interface satisfaction, see a call site --\nnot just diff hunks, which the manual-read checklist in CLAUDE.md requires),\n`diff.patch`, and `issue.md`.\n\n**Never mounted or passed, by construction:** the implementer's\n`agentexec.Result` (summary, captures, stop reason), any prior turn's tool-call\ntranscript, commit messages/git history/branch name (excluded by stripping\n`.git`, not by instruction), daemon internal state, and any other task's data.\nThis is the environmental-enforcement principle applied literally: the\nreviewer is never told \"ignore the implementer's reasoning,\" because there is\nno code path that hands it any.\n\n## 3. Findings contract: `workflow.ReviewFinding`, workflow domain owns it\n\nNot a reuse of `internal/gate.Finding` (`gate.go`), despite the similar\nshape. That type belongs to the Yaegi gate contract (`.archie/gate.go`,\nrepo-owner-authored checks); coupling the review stage's blocking contract to\ngate's evolution would violate \"a domain declares the interface it needs, it\nnever names who implements it.\" `h019.2` implements, in\n`internal/domain/workflow`:\n\n```go\ntype ReviewFinding struct {\n Level string // \"error\" (blocks) | \"warn\" (advisory)\n Category string // dead-code | unchecked-error | hardcoded-value |\n // interface-satisfaction | nil-risk | goroutine-leak |\n // race | other -- CLAUDE.md's own checklist categories\n File string\n Line int\n Message string\n}\n\nfunc ReviewBlocking(findings []ReviewFinding) bool // mirrors gate.Blocking\n```\n\nThe domain owns the type and the pure blocking decision; turning the\nreviewer agent's raw output into `[]ReviewFinding` is app/infrastructure code\n(`h019.3`/`h019.4`), not domain code -- same direction as gate's Yaegi\nevaluator producing `[]gate.Finding` for the domain to consume.\n\n**Findings are reported through a structured capture tool**, the same\n`agentexec.CaptureTool` pattern `feasibility.go`'s `decideCaptureTools`\nalready uses, not free text the caller regexes out of a final message. This\nis the findings contract's own application of environmental enforcement:\nthe reviewer cannot end its turn without calling a typed tool, rather than\nbeing asked to format its answer as JSON and trusted to comply.\n\n## 4. Lifecycle effect of a surviving finding: `StatusParked`, not `WaitingHuman`\n\nThe epic's acceptance criteria say a surviving finding \"parks the task as\n`waiting_human`,\" which names two different states in the actual machine\n(`internal/taskstate/taskstate.go`). This decides between them:\n**`store.StatusParked`**, following `StageDiffCap`'s existing precedent\n(`steps.go`) exactly -- a stage-computed policy stop with a `Detail`\nexplaining why, before PR open. `Parked`'s available actions, retry and\nabandon, are the right shape here: fix the flagged code and retry, or\nabandon/override if a finding is a false positive. `WaitingHuman`'s\napprove/reject actions have no obvious referent -- there is no PR yet to\napprove or reject.\n\nA `Level == \"error\"` finding that survives sets\n`tc.Outcome = Outcome{Status: store.StatusParked, Detail: \u003crendered findings\u003e}`\nand the stage returns `nil`; `StageOpenPR` never runs. `Level == \"warn\"`\nfindings, and the zero-findings case, leave `tc.Outcome` unset and the stage\nreturns `nil`, so `StageOpenPR` runs next. Attaching warn-level findings to\nthe task record for PR-body/dashboard display is `h019.6`'s job, not decided\nhere.\n\n**A review that fails to run is fail-closed.** The\nblocking rule is `Verdict == confirmed \u0026\u0026 Level == error`, so only a confirmed\nfinding blocks -- but that governs findings, not the reviewer's own failure. A\nsub-agent that errors, is truncated, or produces no conclusion yields\n`ReviewStatusNotRun`, for which `ReviewReport.Passed()` is false and\n`Blocking()` is also false; the contract deliberately refuses to guess. This\nstage resolves that as **park, do not open the PR**. The reasoning is that\n`Repo.ReviewEnabled` is opt-in: an operator who turned the gate on wants the\ngate, and a provider outage silently degrading into \"PR opened unreviewed\" is\nthe failure they were buying protection against. The cost is accepted -- a\ntransient model error parks a task, and `Parked`'s retry action is the\nremedy. `Detail` must say the review did not run, never that it passed.\n\nNote this is why `h019.2` models \"ran and found nothing\" separately from \"did\nnot run\": collapsing them to an empty slice would make an outage\nindistinguishable from a clean review, and fail-closed unimplementable.\n\n## 5. Model, effort, and whether a repo even runs this yet\n\n**Model:** a new `\"reviewer\"` key in the existing `Config.Models` map (already\na generic `map[string]string`, no schema change) with the same single-level\nfallback precedent `agent.go` already uses for planner-\u003ebuilder:\n`Models[\"reviewer\"]`, falling back to `Models[\"builder\"]` if unset. Operators\nwho want a genuinely independent second opinion configure a distinct model;\nnothing forces one, because CLAUDE.md's project scope is \"smallest change\nthat works,\" not a mandated model-diversity policy.\n\n**Effort/budget:** reuse the per-stage budget override `AgentStage` already\nsupports (`agent.go`), not a new config surface -- a repo wanting a\ncheaper or more thorough reviewer sets `MaxSteps` the same way\nthe plan stage already can. Map that budget onto `Subagent.MaxSteps` and\n`Subagent.MaxTokens` deliberately: **`MaxTokens` is a per-call ceiling, not a\ncumulative budget**, so an N-step reviewer can emit up to N x `MaxTokens`.\nSetting it as though it bounded the whole run is a costing error, not a\nsafety one. `Subagent.MaxSteps` defaults to 10 when unset.\n\n**Observability:** the nested run is synchronous and non-streaming -- nothing\nis emitted between the parent's call and its result, so a long review reads as\na stalled stage. Emit task events around the call so the dashboard shows the\nreviewer working rather than a gap.\n\n**Opt-in, not automatic:** `h019.5` (calibration -- confirm findings\nadversarially before they surface) is a separate, lower-priority bead than\n`h019.4` (wiring). Shipping the stage unconditionally the moment `h019.4`\nlands would gate every existing repo's PR flow on an uncalibrated reviewer\nbefore calibration exists, which is exactly the \"reviewer that cries wolf\"\nrisk the epic names as the thing that kills this feature. `h019.4` adds\n`Repo.ReviewEnabled bool` (default `false`) to `internal/config`; an operator\nopts a repo in once they trust it, the same shape as any other per-repo gate\nsetting.\n\n## Packages this touches\n\n- `internal/domain/workflow` (`h019.2`, `h019.4`): `ReviewFinding`,\n `ReviewReport`, `ReviewBlocking` -- shipped -- and a `ReviewStage` inserted\n between `StageDiffCap` and `StageOpenPR` in `implement.go`. The domain owns\n the contract and the pure blocking decision, and declares the reviewer\n interface it needs; it never names `agent.Subagent`.\n- `internal/worktree` or a sibling package (`h019.3`): the clean-snapshot\n export (`git archive`, no `.git`) building the reviewer's isolated\n workspace. Still required -- `Subagent` isolates conversation, not\n filesystem.\n- `internal/app/agentworker` (`h019.3`): constructs the `agent.Subagent` from\n the worker's own resolved provider (`agentexec.NewRuntime`), with a\n read-only toolset rooted at the snapshot and the findings capture tool. This\n is app-layer wiring: the domain gets an implementation of its reviewer\n interface, not an SDK type.\n- `internal/config` (`h019.4`): `Models[\"reviewer\"]` (no type change) and\n `Repo.ReviewEnabled bool`.\n- `internal/store`/`internal/taskstate`: unchanged; reuses `StatusParked`.\n- Surfacing findings on the PR body and dashboard is `h019.6`, out of scope\n here.\n\n## What this does not decide\n\nThe exact review checklist prompt content, how many findings can survive\nbefore `MaxSteps` is exhausted, and the adversarial-confirmation mechanism\nthat keeps a finding from surfacing on a single reviewer's say-so are\n`h019.5`. The PR-body/dashboard rendering of findings is `h019.6`. This\ndocument decides isolation, inputs, the findings contract's owner and shape,\nthe lifecycle effect, and model/effort/opt-in configuration only.\n" }, + { + "url": "/dev/prds/agent2agent-protocol/", + "title": "Agent2Agent as archie's agent-to-agent protocol — decision", + "section": "PRDs", + "body": "# Agent2Agent as archie's agent-to-agent protocol — decision\n\n**Status:** Draft\n**Date:** 2026-09-22\n**Authority:** the A2A Protocol Specification v1.0.0 (`a2a-protocol.org`) for the\nprotocol, `docs/architecture/organisation.md` for package placement, and\n`docs/architecture/migration-decisions.md` §2 for session and messaging design.\n\n## Decision\n\nA2A is the protocol archie speaks to other agents. It carries agent-to-agent\nwork: discovery of what a remote agent offers, delegation of a unit of work to it,\nprogress on that work, and the artifacts it produces.\n\n## Layers\n\n**MCP stays the tool layer.** MCP connects a model to tools and data; A2A connects\nagents to agents. They are complementary and archie runs both:\n`internal/tools/provider` registers MCP providers as optional capabilities, so an\nA2A call and an MCP tool call are different kinds of traffic with different\nowners.\n\n**A2A rides archie's existing transports.** A2A's canonical data model is\nProtocol Buffer messages and it defines a gRPC binding, so archie speaks A2A over\nthe gRPC and NATS it already runs. A second wire format, a second broker, or a\nbespoke protocol for agent-to-agent traffic is a requirement not to introduce.\n\n## Where A2A stops\n\nA2A is not a general replacement for either of the two protocols archie already\nhas, and each boundary is a requirement rather than a preference.\n\n- **`internal/domain/messaging` stays the human and channel layer.** A\n Conversation is a ChannelID and a ThreadID, its participants are people on\n Telegram, email, webhook and the dashboard, and its records are what a curator\n reads. An A2A peer is not a channel participant and does not address a\n Conversation.\n- **`internal/agentexec` stays the daemon-to-worker execution protocol.** It\n carries a Request, a Result, gate and budget policy, and capture tools between\n the daemon and the agent container it owns. An A2A peer never receives that\n protocol, and A2A never carries gate, budget or protection policy.\n\nA2A is therefore an edge protocol: it exchanges work with peers outside archie's\nown process boundary, and it composes with the two protocols above rather than\nreplacing or abstracting them.\n\n## A2A Task mapping\n\n**Decision: archie's work lifecycle is mapped to A2A's, not expressed in it. An\nA2A Task is a view over archie's own task, and archie's status remains the record\nof truth.**\n\nThis is the load-bearing decision, because A2A's Task carries its own state\nmachine and archie's lifecycle is the on-disk format of its task store, whose\nstatus strings a rename migrates rather than changes.\n\nThe mapping is partial, and each gap is a case where archie knows something A2A's\nstates do not carry:\n\n- **Completion by another system.** A2A's terminal states describe what the agent\n did (`completed`, `failed`, `canceled`, `rejected`). archie's `merged` and\n `rejected` describe what a forge did to a pull request after archie finished\n its work. There is no A2A state for \"an external system accepted this\", so a\n completed A2A task cannot express the outcome that matters most to the caller.\n- **Handing work to a reviewer.** archie's `pr_open` means the work left\n archie's hands for human review. A2A's `input-required` is the nearest state,\n but it means the *client* must send more input, and a reviewer is not the\n client.\n- **Operator decisions.** `declined`, `parked` and `dead` are outcomes of\n archie's own policy and operator actions. A2A has no state for \"the operator\n refused this\" or \"a budget ran out and an operator must decide\".\n\nA WorkflowExecution is the unit an A2A task maps onto, because it is the attempt\nthat runs, streams and produces artifacts, and a follow-up attempt is a new\nexecution. A2A's own model agrees that a task is immutable once terminal and that\na refinement is a new task sharing the `contextId`, which is why archie's\nper-attempt executions and A2A's per-request tasks correspond.\n\n**Requirement:** the A2A state a peer sees is derived from archie's status by one\nmapping, and archie's status is carried on the task so a peer can read what the\nderivation lost. The mapping is total in the direction that matters -- every\narchie status has an A2A state -- and deliberately not injective, because the\ngaps above are facts A2A cannot hold.\n\n**Requirement:** adopting A2A's state names as archie's persisted task status is\nrejected. It would migrate the task store, and it would drop the forge outcomes\nthat tell a caller whether the work was accepted.\n\n## What an A2A agent is\n\n**An A2A agent is an archie Identity.** The Agent Card describes a durable,\naddressable actor with an endpoint, capabilities and authentication requirements,\nand an Identity is the actor archie persists, versions, suspends and scopes\ncredentials to.\n\nAn `agent.Persona` is not an A2A agent: a persona is prompt text selected for a\nturn, and it has no endpoint or credential. An agent container is not an A2A\nagent: it is task-scoped and ephemeral, and it terminates with the work it ran.\nThe daemon is not an A2A agent: it is the process that serves the identity.\n\n## The Agent Card\n\n**The Gateway serves the card, for the identity it is configured as.** A2A's\n\"Get Agent Card\" is an abstract operation with a gRPC binding, so the card is\nserved through the binding archie runs and needs no HTTP listener.\n\n**The card is derived, never hand-written.** Its skills come from the skill\ncatalog, its identity from the configured Identity, and its capabilities from\nwhat the process already advertises about itself. A card that restated\ncapabilities independently would be a second inventory of the same facts, which\nis the class of drift the existing capability reporting exists to prevent.\n\n**The card advertises the authentication archie applies**, and it carries no\nsecret. A card that named a token would be a credential published at a\nwell-known location.\n\n## Server before client\n\n**archie is an A2A server first.** Accepting A2A calls is the smaller direction\nand the more valuable one: the work a peer would delegate -- an issue taken to a\npull request, through archie's gates, worktrees and review -- exists only inside\narchie, and archie already serves its own contracts over gRPC to the Messaging\nService, the dashboard and the State Store. Acting as an A2A client to remote\nagents is a later capability, and one that consumes the same contract.\n\n## Authentication and authorization\n\n**An inbound A2A call is authenticated at the transport, by the same bearer-token\ninterceptor the Gateway applies to its other contracts.** A2A carries no identity\nin its payload by design: identity is established where the connection is, so the\ntransport token is the identity and no field in a Message or Task names a caller.\n\n**Authorization is per skill**, which is A2A's own model: the card advertises\nskills, and a caller may invoke the skills its credential is scoped to.\n\n**Task-scoped grants are not A2A credentials.** They scope a worker's access to\none task's records inside the State Store and are issued by the daemon for its own\ncontainers. Reusing one as an inbound A2A credential would let a peer act with a\nworker's authority, which is the isolation the grants exist to enforce.\n\n**The dashboard's authentication is not an A2A scheme.** It gates an operator\ninterface, not an endpoint that agents call, so it authenticates no A2A request.\n\n## Package placement\n\n- The contract -- A2A's data model, operations and the mapping from archie's\n status -- lives in `internal/domain/\u003carea\u003e/`.\n- The binding that carries it over gRPC lives in `internal/infrastructure/`,\n beside the existing gRPC clients and servers.\n- Wiring of the contract to the Gateway and the task store lives in\n `internal/app/`.\n\n## Verification\n\n- A peer fetches the Agent Card over gRPC and receives the configured identity's\n identity, skills and authentication requirements.\n- A delegated task reaches an archie task, and the A2A state a peer observes\n changes as archie's status changes, through the one mapping.\n- A task that reaches `merged` reports an A2A state derived from it, and the\n archie status is readable on the task.\n- A call with no credential, and a call with a credential scoped to another\n skill, are both refused, with the refusal A2A defines for them.\n- A task-scoped grant presented as an inbound A2A credential is refused.\n- No A2A traffic reaches `internal/domain/messaging` or `internal/agentexec`.\n" + }, { "url": "/dev/prds/binding-secret-encryption/", "title": "Binding secret at-rest encryption -- decision", @@ -485,6 +491,10 @@ "title": "Adversarial self-review stage -- decision", "url": "/dev/prds/adversarial-self-review/" }, + { + "title": "Agent2Agent as archie's agent-to-agent protocol — decision", + "url": "/dev/prds/agent2agent-protocol/" + }, { "title": "Binding secret at-rest encryption -- decision", "url": "/dev/prds/binding-secret-encryption/" diff --git a/docs/prds/agent2agent-protocol.md b/docs/prds/agent2agent-protocol.md new file mode 100644 index 000000000..885726f80 --- /dev/null +++ b/docs/prds/agent2agent-protocol.md @@ -0,0 +1,164 @@ +# Agent2Agent as archie's agent-to-agent protocol — decision + +**Status:** Draft +**Date:** 2026-09-22 +**Authority:** the A2A Protocol Specification v1.0.0 (`a2a-protocol.org`) for the +protocol, `docs/architecture/organisation.md` for package placement, and +`docs/architecture/migration-decisions.md` §2 for session and messaging design. + +## Decision + +A2A is the protocol archie speaks to other agents. It carries agent-to-agent +work: discovery of what a remote agent offers, delegation of a unit of work to it, +progress on that work, and the artifacts it produces. + +## Layers + +**MCP stays the tool layer.** MCP connects a model to tools and data; A2A connects +agents to agents. They are complementary and archie runs both: +`internal/tools/provider` registers MCP providers as optional capabilities, so an +A2A call and an MCP tool call are different kinds of traffic with different +owners. + +**A2A rides archie's existing transports.** A2A's canonical data model is +Protocol Buffer messages and it defines a gRPC binding, so archie speaks A2A over +the gRPC and NATS it already runs. A second wire format, a second broker, or a +bespoke protocol for agent-to-agent traffic is a requirement not to introduce. + +## Where A2A stops + +A2A is not a general replacement for either of the two protocols archie already +has, and each boundary is a requirement rather than a preference. + +- **`internal/domain/messaging` stays the human and channel layer.** A + Conversation is a ChannelID and a ThreadID, its participants are people on + Telegram, email, webhook and the dashboard, and its records are what a curator + reads. An A2A peer is not a channel participant and does not address a + Conversation. +- **`internal/agentexec` stays the daemon-to-worker execution protocol.** It + carries a Request, a Result, gate and budget policy, and capture tools between + the daemon and the agent container it owns. An A2A peer never receives that + protocol, and A2A never carries gate, budget or protection policy. + +A2A is therefore an edge protocol: it exchanges work with peers outside archie's +own process boundary, and it composes with the two protocols above rather than +replacing or abstracting them. + +## A2A Task mapping + +**Decision: archie's work lifecycle is mapped to A2A's, not expressed in it. An +A2A Task is a view over archie's own task, and archie's status remains the record +of truth.** + +This is the load-bearing decision, because A2A's Task carries its own state +machine and archie's lifecycle is the on-disk format of its task store, whose +status strings a rename migrates rather than changes. + +The mapping is partial, and each gap is a case where archie knows something A2A's +states do not carry: + +- **Completion by another system.** A2A's terminal states describe what the agent + did (`completed`, `failed`, `canceled`, `rejected`). archie's `merged` and + `rejected` describe what a forge did to a pull request after archie finished + its work. There is no A2A state for "an external system accepted this", so a + completed A2A task cannot express the outcome that matters most to the caller. +- **Handing work to a reviewer.** archie's `pr_open` means the work left + archie's hands for human review. A2A's `input-required` is the nearest state, + but it means the *client* must send more input, and a reviewer is not the + client. +- **Operator decisions.** `declined`, `parked` and `dead` are outcomes of + archie's own policy and operator actions. A2A has no state for "the operator + refused this" or "a budget ran out and an operator must decide". + +A WorkflowExecution is the unit an A2A task maps onto, because it is the attempt +that runs, streams and produces artifacts, and a follow-up attempt is a new +execution. A2A's own model agrees that a task is immutable once terminal and that +a refinement is a new task sharing the `contextId`, which is why archie's +per-attempt executions and A2A's per-request tasks correspond. + +**Requirement:** the A2A state a peer sees is derived from archie's status by one +mapping, and archie's status is carried on the task so a peer can read what the +derivation lost. The mapping is total in the direction that matters -- every +archie status has an A2A state -- and deliberately not injective, because the +gaps above are facts A2A cannot hold. + +**Requirement:** adopting A2A's state names as archie's persisted task status is +rejected. It would migrate the task store, and it would drop the forge outcomes +that tell a caller whether the work was accepted. + +## What an A2A agent is + +**An A2A agent is an archie Identity.** The Agent Card describes a durable, +addressable actor with an endpoint, capabilities and authentication requirements, +and an Identity is the actor archie persists, versions, suspends and scopes +credentials to. + +An `agent.Persona` is not an A2A agent: a persona is prompt text selected for a +turn, and it has no endpoint or credential. An agent container is not an A2A +agent: it is task-scoped and ephemeral, and it terminates with the work it ran. +The daemon is not an A2A agent: it is the process that serves the identity. + +## The Agent Card + +**The Gateway serves the card, for the identity it is configured as.** A2A's +"Get Agent Card" is an abstract operation with a gRPC binding, so the card is +served through the binding archie runs and needs no HTTP listener. + +**The card is derived, never hand-written.** Its skills come from the skill +catalog, its identity from the configured Identity, and its capabilities from +what the process already advertises about itself. A card that restated +capabilities independently would be a second inventory of the same facts, which +is the class of drift the existing capability reporting exists to prevent. + +**The card advertises the authentication archie applies**, and it carries no +secret. A card that named a token would be a credential published at a +well-known location. + +## Server before client + +**archie is an A2A server first.** Accepting A2A calls is the smaller direction +and the more valuable one: the work a peer would delegate -- an issue taken to a +pull request, through archie's gates, worktrees and review -- exists only inside +archie, and archie already serves its own contracts over gRPC to the Messaging +Service, the dashboard and the State Store. Acting as an A2A client to remote +agents is a later capability, and one that consumes the same contract. + +## Authentication and authorization + +**An inbound A2A call is authenticated at the transport, by the same bearer-token +interceptor the Gateway applies to its other contracts.** A2A carries no identity +in its payload by design: identity is established where the connection is, so the +transport token is the identity and no field in a Message or Task names a caller. + +**Authorization is per skill**, which is A2A's own model: the card advertises +skills, and a caller may invoke the skills its credential is scoped to. + +**Task-scoped grants are not A2A credentials.** They scope a worker's access to +one task's records inside the State Store and are issued by the daemon for its own +containers. Reusing one as an inbound A2A credential would let a peer act with a +worker's authority, which is the isolation the grants exist to enforce. + +**The dashboard's authentication is not an A2A scheme.** It gates an operator +interface, not an endpoint that agents call, so it authenticates no A2A request. + +## Package placement + +- The contract -- A2A's data model, operations and the mapping from archie's + status -- lives in `internal/domain//`. +- The binding that carries it over gRPC lives in `internal/infrastructure/`, + beside the existing gRPC clients and servers. +- Wiring of the contract to the Gateway and the task store lives in + `internal/app/`. + +## Verification + +- A peer fetches the Agent Card over gRPC and receives the configured identity's + identity, skills and authentication requirements. +- A delegated task reaches an archie task, and the A2A state a peer observes + changes as archie's status changes, through the one mapping. +- A task that reaches `merged` reports an A2A state derived from it, and the + archie status is readable on the task. +- A call with no credential, and a call with a credential scoped to another + skill, are both refused, with the refusal A2A defines for them. +- A task-scoped grant presented as an inbound A2A credential is refused. +- No A2A traffic reaches `internal/domain/messaging` or `internal/agentexec`.