@@ -68,7 +68,7 @@ VS Code also detects plain `.md` files in `.github/agents/`.
6868The body is prepended to every user prompt when the agent is active. Keep it focused and
6969purposeful — include only what genuinely changes the agent's behavior.
7070
71- For the full list of frontmatter properties, read ` references/frontmatter.md ` .
71+ For the full list of frontmatter properties, read ` references/frontmatter.md ` .
7272For all available tool names, read ` references/tools.md ` .
7373
7474---
@@ -173,6 +173,73 @@ See `references/patterns.md` for an orchestrator pattern.
173173
174174---
175175
176+ ## Multi-Step Protocols and Sub-Agents
177+
178+ When an agent body has a numbered protocol with ** distinct, independent steps** , each
179+ step should be delegated to a separate sub-agent invocation rather than executed in a
180+ single context. This prevents context window bloat, reduces interference between steps,
181+ and allows independent steps to run in parallel.
182+
183+ ### When to apply this pattern
184+
185+ Use sub-agents for individual protocol steps when ** all** of these are true:
186+ - The agent has 3 or more protocol steps
187+ - Each step has a clearly different focus (e.g., explore, implement, verify)
188+ - Steps do not need to carry the full accumulated context of earlier steps
189+
190+ ### How to write the protocol
191+
192+ Instead of describing steps as inline instructions, tell the agent to invoke a
193+ sub-agent for each step:
194+
195+ ```` markdown
196+ ## Protocol
197+
198+ This agent executes each step in a separate sub-agent to keep contexts lean.
199+
200+ ### Step 1 — <name >
201+ Invoke a sub-agent with: "<instruction for step 1 only>"
202+ Output: write result to ` /memories/session/<step1>.md `
203+
204+ ### Step 2 — <name >
205+ Read ` /memories/session/<step1>.md ` , then invoke a sub-agent with: "<instruction >"
206+ Output: write result to ` /memories/session/<step2>.md `
207+
208+ ### Step 3 — <name > (parallel with Step 2 if independent)
209+ Invoke a sub-agent in the ** same turn** as Step 2 with: "<instruction >"
210+ Output: write result to ` /memories/session/<step3>.md `
211+ ````
212+
213+ ### Parallel steps
214+
215+ When two steps don't depend on each other's output, invoke their sub-agents ** in the
216+ same turn** . Annotate this clearly in the protocol:
217+
218+ ```
219+ ② Step A ┐ invoke in the same turn
220+ ② Step B ┘
221+ ③ Step C (depends on A and B — invoke after both finish)
222+ ```
223+
224+ ### Frontmatter requirements
225+
226+ An agent that delegates steps to sub-agents must have ` agent ` in its ` tools ` list.
227+ Use ` agents: ['*'] ` if the sub-agents are ad-hoc (no named ` .agent.md ` files). Use a
228+ named list when the sub-agents are fixed specialist agents.
229+
230+ ``` yaml
231+ tools : ['search', 'read', 'vscode/memory', 'agent']
232+ agents : ['*']
233+ ` ` `
234+
235+ ### Memory handoff between steps
236+
237+ Sub-agents communicate exclusively through ` vscode/memory`. The parent agent writes
238+ a brief for each step before invoking it, and the sub-agent writes its output to a
239+ dedicated memory file when done. The parent reads that file before invoking the next step.
240+
241+ ---
242+
176243# # Security Considerations
177244
178245- Grant agents only the tools they actually need (principle of least privilege)
0 commit comments