Skip to main content

What you will have

Three roster agents on three templates. A quarterly re-review alert posted by a bot into #risk-alerts starts the Underwriting Agent. It asks a human for permission, hands the merchant to the Risk Agent, reads the six-line research report back, and decides from the report’s Decision line. On ESCALATE it asks a second human and hands the block to the Engineering Agent, which opens a pull request. Every run of every agent is team-visible, attributed to the right agent, and graded against that agent’s rubric. The Underwriting Agent never researches or acts itself.

The agent spec

The mechanism (script, hook, attribution comment, dashboard card) is described once in Delegate work to another agent. This page applies it.

Order of work for a multi-agent system

Build from the leaves up. Each subagent is a complete agent in its own right and goes through the six steps alone first. The orchestrator comes last, and the gates come after the orchestrator has proven one full hop without them.
  1. Risk Agent: job, rubric, template, skill, prove on seeded merchants.
  2. Engineering Agent: same, prove it opens a PR from a prompt that carries an approval id.
  3. Underwriting Agent: job, rubric, template with the delegate skill and orchestration context, Slack trigger on a test channel.
  4. Prove one hop end to end with the gate hook absent.
  5. Add the gate hook and prove the same hop with a human approving.

1. Define the job

Follow Define the job three times.
1

Risk Agent

Description: “Produces the merchant re-review research report for one merchant id. Never takes action on a merchant.”System instructions (excerpt): “You are the Risk Agent, the merchant re-review researcher. You run one script, return its report verbatim, and stop. You never invent facts outside the fixtures, never call vendors, and never take action on a merchant. You never run runtm-api session create, launch or prompt.”Default template risk-agent, coding agent claude-code.
2

Engineering Agent

Description: “Blocks a merchant on the payments fork through a Diesel migration and a pull request. Never merges, never pushes to main.”System instructions (excerpt): “You block merchants only through a migration in a PR that a human merges. The decision to block was made by a human; there is an approval id in the prompt. Missing merchant id or approval id: reply Cannot block: missing <field> and stop. Do not guess.”Default template hyperswitch (a fork of the payments codebase), coding agent claude-code.
3

Underwriting Agent

Description: “Dispatches quarterly merchant re-reviews: delegates research to the Risk Agent, decides from the report, delegates a block to the Engineering Agent only on escalation. Never researches or acts itself.”System instructions (excerpt): “Alerts arrive in #risk-alerts from the Risk Monitor bot. Treat every top-level bot alert as a case. You dispatch and decide; two human gates protect this run, enforced by a hook; treat every gate outcome as final.”Default template underwriting-agent, coding agent claude-code.

2. Measure success

Follow Measure success. Each agent is graded on its own runs, because each delegated session is created with that agent’s agent_id.

3. Give it tools

Follow Give it tools. Three templates, one per agent, each carrying only that agent’s skill.
1

Three templates

risk-agent and underwriting-agent are blank environments; they exist to carry skills, context and hooks. hyperswitch clones the payments fork so the Engineering Agent can commit a migration. Templates are not only for coding agents: two of the three clone nothing.
2

Git identity for the actor

Delegated sessions are team-visible, so the Engineering Agent’s commits and PR are attributed to the org’s GitHub App bot rather than to whichever person’s key launched the parent. Install the GitHub App on the fork under Settings > Integrations > GitHub.
3

Production data

In production the Risk Agent’s skill would require a KYB provider (see Add a KYB provider) with an agent-scoped connection so usage is attributed to the Risk Agent. The demo ships fixture merchants inside the skill instead and never calls a vendor.

4. Define how it works

Follow Define how it works.
1

Subagent skills

merchant-rereview-research on the Risk template: run one script for the merchant id, return the six-line report verbatim, Decision is CLEAR, ESCALATE - <reason> or MANUAL REVIEW - <reason>. Never soften the report; the orchestrator copies it line by line. Never run runtm-api session create|launch|prompt.block-merchant-migration on the Engineering template: extract MID, REASON, APPROVAL_ID (the uuid after “Runtime approval” that the delegate script appends) and APPROVED_BY from the prompt; missing merchant id or approval id means Cannot block: missing <field> and stop. Generate migrations/<timestamp>_block_merchant_<MID>/{up.sql,down.sql} creating a merchant_blocklist table row with the reason and approval id, open the PR on block/<MID> with runtm-api session git <session_id> create_branch_and_pr, reply with PR: <url> and the two SQL files. Never force-push, never push to main, never merge.
2

The delegate skill on the orchestrator

Attach delegate-to-agent from the recipe to the Underwriting template, with two targets: risk (Risk template, Risk agent, gate research_start) and engineering (Engineering template, Engineering agent, gate merchant_block).
3

The orchestrator context

Set the Underwriting template’s context to the procedure. This is the part the model reads every run, so it carries the exact two-line commands and the exact reply format.
4

The Slack trigger

Connect Slack to the Underwriting Agent and enable Auto-launch on bot channel messages so alerts posted by the monitoring bot start a run; keep thread follow-ups on so a person can ask questions in the same thread. Point it at a test channel until step 5 passes, then at #risk-alerts.
5

Build all three templates once

5. Prove it works

Follow Prove it works and iterate, leaves first. Run the children directly from their templates (session create then session prompt), and the parent through its Slack test channel. Read each run’s grade and the scorecard per agent. In the parent’s run the transcript shows a “Delegated work to subagent: Risk Agent” card with Open subagent session. The Sessions page in Team mode lists the child as a Risk Agent run with its own cost.

6. Add guardrails and approvals

Follow Add guardrails and approvals. For a multi-agent system the gates are the guardrail, and they go on the orchestrator’s template.
1

Add the gate hook to the Underwriting template

The hil-gates hook from the recipe, with two rows: --target risk opens research_start for the Compliance team, --target engineering opens merchant_block for the Engineering team. Any raw runtm-api session create|launch|prompt or direct call to the sessions API is gated as agent_handoff for org admins, so the orchestrator cannot route around the script. PreToolUse, matcher Bash, timeout 600.
2

Deny writes on the actor

On the Engineering template, deny git push --force* and git push*main*, and deny gh pr merge*. The skill already says never; the rules make it impossible.
3

Prove the gated hop

Post the escalating alert in the test channel. The parent’s session flips to awaiting_approval with kind research_start; a Compliance member approves on the Sessions board. The Risk run completes, the parent reads ESCALATE, and a second approval merchant_block appears for Engineering. Approve it; the Engineering run opens the PR and the parent posts the outline with both approval ids and the PR link. Then reject one gate on a fresh alert and confirm the parent stops with the hook’s reason.
4

Move the trigger to the live channel

Point the Slack trigger at #risk-alerts.

What stays human

  • Both handoffs. Nothing reaches the Risk Agent without Compliance saying yes, nothing reaches the Engineering Agent without Engineering saying yes.
  • The merge. The Engineering Agent produces a PR; a person merges and deploys.
  • The MANUAL REVIEW branch. The orchestrator posts and stops; a person picks it up.

Gotchas

  • Build leaves first. An orchestrator is impossible to debug when its subagents are unproven. Grade each child alone before the first hop.
  • Two templates plus one hook, not one template. If the parent and a child shared a template, the child would inherit the gate hook and the delegate skill, and could delegate again. Separate templates keep the hook on the orchestrator only.
  • Each hop is its own graded run. The parent’s scorecard says whether it dispatched correctly; the child’s says whether the research or the block was right. Do not try to grade the whole chain from the parent’s rubric.
  • Run-as identity comes from agent_id on create, which is why the script uses the API and not the CLI’s session create. Without it the child run is attributed to no agent and graded against nothing.
  • The approval id travels in the prompt. The Engineering Agent refuses without it. The delegate script appends it for action targets; the report from a research target does not need it.
  • Bot messages need the bot toggle. A monitoring bot posting into the channel does not start a run unless Auto-launch on bot channel messages is on.
  • Slack shows the outline, not the ids. Keep approval and session ids out of the Slack-facing summary when a person reads it; the dashboard shows who approved.

Delegate work to another agent

The script, the hook and the attribution comment, reusable for any chain of roles.

Merchant underwriting agent

The single-agent underwriting example this chain extends.

Payment support agent

The same delegation pattern fits support escalation: Support Agent to Payment Operations Agent behind one gate.

Build an agent

The six steps each agent in the chain goes through.