Agent Relay
Use this skill when Codex needs real-time coordination across multiple agents. It gives Codex a repeatable workflow for:
- connecting to a Relaycast workspace
- spawning relay-aware workers
- sending direct messages, channel updates, and thread replies
- keeping lead and worker state synchronized through ACK, STATUS, BLOCKED, and DONE signals
Relay fills the peer-to-peer gap in Codex sub-agent workflows. Codex can spawn and collect worker results, but Relaycast gives those workers a shared message bus so they can talk to the lead and to each other.
Auto-setup
On first activation, this skill auto-configures Codex by running scripts/setup.sh. This adds the Relaycast MCP server to .codex/config.toml, enables hooks, installs hooks.json, and copies the relay-worker.toml agent definition. No manual setup is required after installing the skill.
Startup protocol
Every relay-connected Codex agent must complete these steps IN ORDER before substantive work:
Check for a workspace. Call
workspace.listto see if a workspace is already active.- If no workspace is active and
RELAY_API_KEYis set in the environment, callworkspace.set_keywith that key. - If no workspace is active and no key is available, call
workspace.createto auto-create one. This returns a workspace key — save it for workers. - If a workspace is already active, skip to step 2.
- If no workspace is active and
Register as an agent. Call
agent.registerwith your agent name andtype: "agent". UseRELAY_AGENT_NAMEfrom the environment if set, otherwise derive a name from the task context (e.g.,lead,auth-worker).Tell the user they can follow the conversation live at
https://agentrelay.dev/observer?key=<workspace_key>(use the workspace key from step 1). This lets them watch all agent messages in real time.Check the relay inbox. Call
inbox.checkto see if there are any pending messages or task assignments.Send an ACK. If you received a task assignment, send
ACK: <one-sentence understanding>to your lead viadm.send. If the assignment is unclear, sendBLOCKED: <question>instead of guessing.When the task is complete, send
DONE: <summary with evidence>before stopping.
If workspace creation or registration fails, retry once, then report the failure to the user — do not proceed without a relay connection.
Critical rule
Do not assume the current MCP session already has an active Relaycast workspace. Always check with workspace.list first and create or set one if missing.
Working rules
- Include
as: "<agent-name>"on relay calls that support explicit attribution. - Keep the relay identity stable for the whole task. Do not switch names mid-task.
- Check the inbox again after meaningful milestones, before long-running work, and before stopping.
- Prefer direct messages for lead/worker coordination. Use channels only when multiple agents need the same update.
- Keep status messages short, factual, and scoped to the assigned work.
- Do not spawn additional relay workers unless the lead explicitly asks for more delegation.
- If the lead updates the task, follow the newest explicit instruction.
Message templates
ACK: I understand the assignment and I am starting work on <scope>.STATUS: Finished <milestone>; next I am doing <next-step>.BLOCKED: I cannot continue because <blocker>.DONE: Completed <scope>. Evidence: <files changed, commands run, tests, or decisions>.
Two kinds of workers
There are two ways to create workers. Use the right one for the job:
Relaycast workspace agents (preferred for messaging tasks)
Use agent.add to create a Relaycast-native agent. Best for tasks that are primarily about messaging, inbox checks, coordination, or lightweight work that doesn't need a full Codex sub-agent runtime.
Lead steps:
- Ensure workspace exists (call
workspace.list, thenworkspace.createif needed). - Register the lead (
agent.register). - Add the worker with
agent.add(name: "worker-name", type: "agent"). - Send the assignment via
dm.send(to: "worker-name", text: "..."). - Poll lead inbox for ACK (
inbox.check).
Worker steps:
- Check inbox (
inbox.check). - Send ACK to lead via
dm.send. - Perform the assigned scope.
- Send DONE to lead via
dm.send.
Codex sub-agents (for code-heavy tasks)
Use spawn_agent with the relay-worker agent definition for tasks that need full code editing, file access, and tool use. The worker gets its own Codex runtime with Relaycast MCP tools available.
Lead steps:
- Ensure workspace exists and lead is registered (same as above).
- Spawn the worker: include relay name, lead name, workspace key, exact scope, and completion criteria in the task prompt.
- Poll lead inbox for ACK.
Worker steps:
- Call
workspace.set_keywith the workspace key from the task prompt. - Register with
agent.register. - Check inbox, send ACK, do work, send DONE.
Worker ACK fallback
If a worker does not ACK within 30 seconds:
- Check whether the worker appears in
agent.list. - If not listed, register or add the worker directly with
agent.add. - Send (or re-send) the assignment via
dm.send. - Poll the lead inbox again for ACK.
- If still no ACK after a second attempt, report the exact failed step to the user.
Handoff template
Worker: api-worker
Type: relay workspace agent (use agent.add, not spawn_agent)
Lead: lead
Scope: check the Relaycast inbox and confirm connectivity
Protocol:
1. Check inbox
2. DM lead with ACK
3. Perform scope
4. DM lead with DONE
For code-heavy tasks, change the type line to:
Type: Codex sub-agent (use spawn_agent with relay-worker)