|
| 1 | +<instructions> |
| 2 | +You MUST load this guide before you author coordinator and worker agents. |
| 3 | +You MUST model portable multi-agent systems as one coordinator and one or more leaf workers. |
| 4 | +You MUST define the worker <input> block as the public request contract into the worker. |
| 5 | +You MUST mirror each worker <input> field in the caller dispatch process arguments. |
| 6 | +You MUST define a worker response contract in <formats> and capture it in the caller. |
| 7 | +You MUST keep platform-specific invocation syntax inside the caller dispatch layer only. |
| 8 | +You MUST use explicit allowlists for worker selection and tool access. |
| 9 | +You MUST keep worker results task-bounded, typed, and brief. |
| 10 | +You SHOULD use handoffs instead of nested worker spawning when a platform supports handoffs. |
| 11 | +You SHOULD treat undocumented nested delegation as unsupported for portable APS authoring. |
| 12 | +You MUST treat Claude Code workers as leaf workers. |
| 13 | +You SHOULD treat VS Code Copilot and OpenCode workers as leaf workers for portable APS authoring. |
| 14 | +</instructions> |
| 15 | + |
| 16 | +<constants> |
| 17 | +GUIDE_VERSION: "1.0.0" |
| 18 | + |
| 19 | +PLATFORM_CAPABILITY_MATRIX: CSV<< |
| 20 | +platform,coordinator_role,worker_role,documented_depth_policy,invocation_surface,notes |
| 21 | +claude-code,main-thread agent only,markdown subagent,depth-1-only,Agent,"Workers cannot spawn workers." |
| 22 | +vscode-copilot,main chat agent or prompt,subagent or custom agent worker,portable-depth-1,agent/runSubagent,"Custom-agent subagents are experimental and nested delegation is not documented." |
| 23 | +opencode,primary agent,mode=subagent worker,portable-depth-1,Task,"Primary/subagent roles are documented and nested delegation is not documented." |
| 24 | +generic,host-defined or manual APS coordinator,host-defined or external worker,host-defined,host-defined,"Use explicit APS dispatch processes when host behavior is unclear." |
| 25 | +>> |
| 26 | +
|
| 27 | +REQUEST_INTERFACE_RULES: TEXT<< |
| 28 | +1. The worker <input> block is the public interface into the worker. |
| 29 | +2. The caller dispatch process MUST accept the same fields, names, and meanings. |
| 30 | +3. If a platform needs renamed fields, keep the rename in the dispatch layer only. |
| 31 | +4. Do not hide required worker inputs inside free-form prompt text. |
| 32 | +5. Keep request types stable across platforms. |
| 33 | +>> |
| 34 | +
|
| 35 | +RESPONSE_INTERFACE_RULES: TEXT<< |
| 36 | +1. The worker MUST return a typed result that matches a <format> contract. |
| 37 | +2. The caller MUST capture the worker result before the next step starts. |
| 38 | +3. Keep summaries brief and task-bounded. |
| 39 | +4. Do not leak platform-only metadata unless the caller explicitly asks for it. |
| 40 | +>> |
| 41 | +
|
| 42 | +PORTABLE_PATTERNS: JSON<< |
| 43 | +{ |
| 44 | + "coordinator_worker": { |
| 45 | + "description": "One coordinator dispatches one worker and integrates the worker result.", |
| 46 | + "best_for": ["single specialty task", "strong contract boundaries"] |
| 47 | + }, |
| 48 | + "fan_out_review": { |
| 49 | + "description": "One coordinator dispatches multiple leaf workers in parallel and then compares typed results.", |
| 50 | + "best_for": ["research", "review", "verification"] |
| 51 | + }, |
| 52 | + "sequential_handoff": { |
| 53 | + "description": "One worker finishes, returns a typed result, and the coordinator hands off the next step to a different worker.", |
| 54 | + "best_for": ["plan -> implement", "implement -> review"] |
| 55 | + } |
| 56 | +} |
| 57 | +>> |
| 58 | +
|
| 59 | +ANTI_PATTERNS: TEXT<< |
| 60 | +- Worker-to-worker recursion without a documented host contract. |
| 61 | +- Free-form worker prompts with hidden required fields. |
| 62 | +- Caller processes that rename or reshape worker inputs in multiple places. |
| 63 | +- Worker outputs that mix summary text, hidden state, and untyped data. |
| 64 | +- Broad tool access for narrow workers. |
| 65 | +>> |
| 66 | +
|
| 67 | +APS_INTERFACE_EXAMPLE: TEXT<< |
| 68 | +Worker contract: |
| 69 | +<input> |
| 70 | +TICKET_ID: String |
| 71 | +TARGET_PATHS: String[] |
| 72 | +</input> |
| 73 | + |
| 74 | +Caller dispatch process: |
| 75 | +<process id="dispatch-review" name="Dispatch review" args="TICKET_ID: String, TARGET_PATHS: String[]"> |
| 76 | +USE `Agent` where: description="Review the requested files", prompt="Review the requested files", worker="reviewer" |
| 77 | +SET WORKER_REQUEST := { TICKET_ID: TICKET_ID, TARGET_PATHS: TARGET_PATHS } |
| 78 | +CAPTURE REVIEW_RESULT from `reviewer` |
| 79 | +RETURN: REVIEW_RESULT |
| 80 | +</process> |
| 81 | + |
| 82 | +Rule: |
| 83 | +- The caller args are the same interface as the worker input. |
| 84 | +- The caller is responsible for the platform-specific call surface. |
| 85 | +- The worker returns a typed result that the caller captures. |
| 86 | +>> |
| 87 | +
|
| 88 | +BIDIRECTIONAL_CONTRACT_RULE: TEXT<< |
| 89 | +Request flow: caller process args -> worker <input>. |
| 90 | +Response flow: worker <format> result -> caller capture variables. |
| 91 | +The contract is bidirectional only when the caller defines both mappings explicitly. |
| 92 | +>> |
| 93 | +</constants> |
| 94 | +
|
| 95 | +<formats> |
| 96 | +<format id="SUBAGENT_ARCHITECTURE_SPEC_V1" name="Subagent Architecture Spec" purpose="Describe a coordinator plus worker architecture with explicit request and response contracts."> |
| 97 | +# Subagent Architecture Spec: <ARCHITECTURE_NAME> |
| 98 | + |
| 99 | +## Coordinator |
| 100 | +- Role: <COORDINATOR_ROLE> |
| 101 | +- Dispatch surface: <DISPATCH_SURFACE> |
| 102 | +- Depth policy: <DEPTH_POLICY> |
| 103 | + |
| 104 | +## Workers |
| 105 | +| Worker | Role | Input contract | Output contract | Allowed tools | Notes | |
| 106 | +|--------|------|----------------|-----------------|---------------|-------| |
| 107 | +| <WORKER_NAME> | <WORKER_ROLE> | <INPUT_CONTRACT_ID> | <OUTPUT_CONTRACT_ID> | <ALLOWED_TOOLS> | <WORKER_NOTES> | |
| 108 | + |
| 109 | +## Request and response mapping |
| 110 | +<REQUEST_RESPONSE_MAP> |
| 111 | + |
| 112 | +## Failure policy |
| 113 | +<FAILURE_POLICY> |
| 114 | + |
| 115 | +WHERE: |
| 116 | +- <ALLOWED_TOOLS> is String; comma-separated logical or host tool ids allowed for the worker. |
| 117 | +- <ARCHITECTURE_NAME> is String; descriptive name for the coordinator/worker design. |
| 118 | +- <COORDINATOR_ROLE> is String; the coordinator responsibility statement. |
| 119 | +- <DEPTH_POLICY> is String; one of depth-1-only, portable-depth-1, host-defined. |
| 120 | +- <DISPATCH_SURFACE> is String; host invocation surface such as Agent, agent/runSubagent, Task, or manual APS process. |
| 121 | +- <FAILURE_POLICY> is Markdown; what the coordinator does when a worker fails, times out, or returns invalid data. |
| 122 | +- <INPUT_CONTRACT_ID> is String; id or label of the worker request contract. |
| 123 | +- <OUTPUT_CONTRACT_ID> is String; id or label of the worker response contract. |
| 124 | +- <REQUEST_RESPONSE_MAP> is Markdown; explicit mapping from caller args to worker input and from worker result to caller capture. |
| 125 | +- <WORKER_NAME> is String; worker identifier. |
| 126 | +- <WORKER_NOTES> is String; short notes about visibility, allowlists, or platform limits. |
| 127 | +- <WORKER_ROLE> is String; worker responsibility statement. |
| 128 | +</format> |
| 129 | + |
| 130 | +<format id="SUBAGENT_CONTRACT_CHECKLIST_V1" name="Subagent Contract Checklist" purpose="Review checklist for portable coordinator/worker authoring."> |
| 131 | +# Subagent Contract Checklist |
| 132 | + |
| 133 | +- [ ] The coordinator is the single dispatch owner. |
| 134 | +- [ ] Each worker has an explicit APS <input> contract. |
| 135 | +- [ ] Each caller dispatch process mirrors the worker input fields one-for-one. |
| 136 | +- [ ] Each worker returns a typed <format> result. |
| 137 | +- [ ] The caller captures the worker result before the next step starts. |
| 138 | +- [ ] Nested delegation is either documented by the host or avoided. |
| 139 | +- [ ] Worker tool access uses least privilege. |
| 140 | +- [ ] Worker visibility and allowlists are explicit. |
| 141 | +- [ ] Platform-only routing details stay outside the portable contract. |
| 142 | + |
| 143 | +WHERE: |
| 144 | +- This checklist is a fixed review format with no placeholders. |
| 145 | +</format> |
| 146 | +</formats> |
0 commit comments