139: "Who can I ask?" — discover teammate agents by skill and engage them; publish cards for hosted personas
Part of the cross-repo epic #2785. This is the consumer issue — the one that makes the ecosystem come alive. Depends on the directory from relaycast#294 and the shared card contract from workforce#296.
Why
The Factory turns issues into reviewed PRs by spawning worker agents. Today, when a worker hits a question it can't answer, it has nowhere to turn — Factory only discovers fleet nodes/capabilities for placement (FleetClient.roster()), not agents by skill, and there's no path to actually ask another agent. Once every proactive agent publishes an A2A card and registers with the Relaycast directory, a Factory worker should be able to: "who can answer X?" → pick an agent by its card skills → send it the question and get a reply.
What
1. Directory-backed peer discovery
Add a card-aware lookup alongside roster() in FleetClient (src/ports/fleet.ts), implemented in RelayFleetClient (src/fleet/relay-fleet-client.ts) — query Relaycast's GET /v1/a2a/directory filtered by skill/tag, returning { name, skills[], url, kind } per candidate. Optionally cache via an in-package index like RelayflowPolicyRegistry (src/dispatch/relayflow-registry.ts).
2. "Ask a teammate" capability
Give a running worker a way to engage a discovered peer: resolve target via #1, then send over Relaycast — A2A POST /a2a/rpc message/send or the broker seam (FleetClient.sendMessage/waitForInjected/onAgentMessage). Reuse the existing DM/relay path; don't invent a new transport. Surface it as a discrete capability/tool the worker invokes mid-task, with a bounded wait for the reply.
3. Publish cards for factory-hosted personas
Generate an A2A card for factory-hosted personas (e.g. .agentworkforce/agents/factory-feature-guardian/persona.json) via @agentworkforce/persona-kit deriveAgentCard ([workforce#296]) and publish it when the persona-backed node comes online — createFactoryNodeDefinition (src/node/factory-node.ts) already assembles capabilities/tags/metadata and calls defineNode. Export the new surface from src/index.ts.
Acceptance
- A
FleetClientmethod returns teammate agents matching a skill/tag from the Relaycast directory (with how to reach each). - A worker can, mid-task, ask a discovered teammate a question and receive a reply (bounded wait).
- Factory-hosted personas publish a
deriveAgentCard-derived card when their node comes online; they appear in the directory. - New surface exported from
src/index.ts; card schema consumed from@relaycast/a2a(no hand-rolled shape).
✅ End-to-end verification — Factory success criteria (REQUIRED)
This issue IS the "does the ecosystem come alive?" proof. "Compiles" is nowhere near done — the Factory must run a real discover → ask → reply round trip and observe the reply arrive, then check the harness in. Use agent-relay's in-process broker so this runs locally with no external services (src/fleet/internal-fleet-client.ts, src/fleet/ensure-relay-broker.ts).
Run it
npm run build
npm test # vitest run (add the E2E below)
The E2E (test/e2e/ask-a-teammate.test.ts, runnable via npm test) must:
- Stand up a local directory (mock the Relaycast
/v1/a2a/directoryHTTP response, or seed the in-process broker) with two agents whose cards declare distinct skills (e.g.["infra-watch"],["code-review"]). - Call the new Factory discovery method with
skill: "infra-watch"→ assert it returns only the infra agent, with an address to reach it. - Stand up a stub teammate agent on the in-process broker (
InternalFleetClient+ensureRelayBroker) that replies to an inbound question with a canned answer. - From a simulated worker, invoke the new "ask a teammate" capability against the discovered agent → assert the question is delivered and the canned reply is received within the bounded wait.
- For persona cards: bring a factory-hosted persona node online via
createFactoryNodeDefinition, then assert itsderiveAgentCard-derived card was published/registered and shows up in the directory lookup from step 2.
Observe (must pass)
- Discovery returns the right agent for a skill and
[]for an unknown skill. - The worker actually receives the teammate's reply over the relay path (the round trip completes, not just "message sent").
- A factory-hosted persona is discoverable by its skill after its node comes online.
Deliverable
-
test/e2e/ask-a-teammate.test.tsrunning the full discover→ask→reply round trip against the in-process broker + mock directory, one command (npm test). - The E2E fails if discovery returns everything unfiltered, if the reply never arrives, or if persona-card publishing is removed (no false green).
Anchor files
src/ports/fleet.ts(FleetClient,RosterEntry,sendMessage/waitForInjected/onAgentMessage)src/fleet/relay-fleet-client.ts,src/fleet/internal-fleet-client.ts,src/fleet/ensure-relay-broker.tssrc/dispatch/relayflow-registry.ts(in-package registry precedent)src/node/factory-node.ts(createFactoryNodeDefinition),src/index.ts(public barrel).agentworkforce/agents/factory-feature-guardian/persona.json(proto card / template)planning/linear-issue-cloud-proactive-runtime-fleet-unification.md,planning/factory-unified-node-architecture-linear-issue.md
Fixes #139
Summary by cubic
Workers can discover teammate agents by skill and ask them; Factory‑hosted personas publish canonical A2A cards. Previously there was no skill discovery or persona publishing; now asks are bounded, match replies to the real sender, quarantine uncorrelated timeouts, surface definitive delivery rejections, and clear duplicate‑delivery markers when the original send is proven failed.
-
Discovery and ask:
FleetClient.discoverTeammates({ skill | tag | q })queries a Relaycast directory viaRelaycastTeammateDirectory.askTeammate(...)awaits message transport readiness and the socket handshake, ignores pre‑send replies, prevents overlapping asks to the same teammate from the same requester (scoped per client), drains late replies, quarantines timed‑out asks, matches replies viaeffectiveSender(), and throwsFleetDeliveryRejectedErroron rejection. AddsdiscoverTeammates, asynceffectiveSender(), andwhenMessagesObservable()toFleetClient; exportsaskTeammate,RelaycastTeammateDirectory. Packsbin/factory.mjs teammate-mcpto extend the injected Agent Relay MCP server so workers gain discover/ask without losing Relay tools or identity;InternalFleetClientresolves this by default. -
Persona cards: derive with
@agentworkforce/persona-kit’s canonical mapper, validate with@relaycast/a2a, and publish viaRelaycastAgentCardPublisherwith retry and 409 handling.startFactoryNode({ cardPublisher })publishes on node registration and exposescardPublished. The default@agent-relay/factory/nodehosts no persona; cloud personas are unchanged. -
Relay workspace scoping: identify message streams by Relay workspace ID, canonicalize connection stream paths and missing receipt parents, fail closed on unknown streams, and preserve identity across rebinds.
createFleetaccepts and forwardsmessageStreamScope; passRELAY_WORKSPACE_KEYas bothRELAY_WORKSPACE_KEYandRELAY_API_KEY. -
Tests: E2E
test/e2e/ask-a-teammate.test.tsexercises discover → ask → reply and persona card publication; unit tests cover MCP tools, directory filtering, reply identity, transport readiness/handshake, timeouts/quarantine, duplicate‑delivery marker clearing, and relay/internal backends. -
Migration
- Upgrade to Node 22+.
- Set
RELAY_WORKSPACE_KEYin worker environments (and use it asRELAY_API_KEY) when using the Relay backend.