Skip to content

Commit af3fc48

Browse files
authored
feat: add inline sub-agent syntax using ## agent: \name\`` / H2 boundary delimiters with per-engine placement (experimental) (#29668)
1 parent c681553 commit af3fc48

243 files changed

Lines changed: 1963 additions & 106 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/patch-add-inline-sub-agent-syntax.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/aw/subagents.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
description: Guide for defining inline sub-agents in workflow markdown files — syntax, feature flag, engine placement, frontmatter fields, and best practices.
3+
---
4+
5+
# Inline Sub-Agents
6+
7+
Inline sub-agents let you define specialised agents directly inside a workflow markdown file. At runtime the sub-agent sections are extracted from the prompt (after `{{#runtime-import}}` macros are resolved) and written to the engine-specific agents directory so the engine CLI can discover and invoke them.
8+
9+
> **Experimental feature.** Compilation emits `⚠ Using experimental feature: inline-sub-agents` whenever a workflow contains at least one `## agent:` block.
10+
11+
---
12+
13+
## Enabling the Feature
14+
15+
Inline sub-agent extraction and restoration steps are **only compiled in when the `inline-agents` feature flag is set**:
16+
17+
```yaml
18+
---
19+
engine: copilot
20+
features:
21+
inline-agents: true
22+
---
23+
```
24+
25+
Without this flag the `## agent:` sections are stripped from the prompt at compile time but no upload or restore steps are generated, so the sub-agent files will not be available during the agent job.
26+
27+
---
28+
29+
## Syntax
30+
31+
Define a sub-agent with a level-2 Markdown heading of the form `## agent: \`name\``:
32+
33+
```markdown
34+
## agent: `file-summarizer`
35+
---
36+
description: Summarizes the content of a file in a few concise sentences
37+
model: claude-haiku-4.5
38+
---
39+
You are a file summarization assistant. When given a file path, read the
40+
file and return a brief summary (2–4 sentences) describing its purpose
41+
and key contents. Be concise and factual.
42+
```
43+
44+
### Name rules
45+
46+
- Must be enclosed in backticks: `` `name` ``
47+
- Lowercase only: `[a-z][a-z0-9_-]*`
48+
- Examples: `` `planner` ``, `` `file-summarizer` ``, `` `code-reviewer` ``
49+
50+
### Block boundary
51+
52+
The block ends at the next `##` heading (any level-2 heading) or at EOF — no explicit end marker is needed. Place sub-agent blocks **at the bottom** of the file, after all main workflow content.
53+
54+
### Frontmatter fields
55+
56+
Only two fields are supported inside a sub-agent frontmatter block:
57+
58+
| Field | Required | Default | Notes |
59+
|---|---|---|---|
60+
| `description` | No || Human-readable summary of the sub-agent's role |
61+
| `model` | No | `"inherited"` | Model override; `"inherited"` uses the parent workflow's model |
62+
63+
All other fields (`engine`, `tools`, `network`, etc.) are stripped at runtime with a warning. Sub-agents inherit the parent's engine, tool access, and network configuration.
64+
65+
---
66+
67+
## Engine-Specific Placement
68+
69+
Sub-agent files are written to the directory and with the extension each engine natively expects:
70+
71+
| Engine | Directory | Extension |
72+
|---|---|---|
73+
| Copilot (default) | `.agents/agents/` | `.agent.md` |
74+
| Claude | `.claude/agents/` | `.md` |
75+
| Codex | `.codex/agents/` | `.md` |
76+
| Gemini | `.gemini/agents/` | `.md` |
77+
78+
The engine is detected at compile time from the `engine:` field and injected as `GH_AW_ENGINE_ID` into the interpolation step's environment.
79+
80+
---
81+
82+
## MCP Access in Sub-Agents
83+
84+
Sub-agents **do not have their own MCP servers**. They run within the parent workflow's agent environment but without independent tool configuration.
85+
86+
For sub-agents to perform useful work they typically need access to the file system and shell. The following tools must be enabled on the parent workflow:
87+
88+
- **`cli-proxy: true`** — enables the GitHub CLI proxy so the sub-agent can make authenticated GitHub API calls via `gh`. Strongly recommended for any sub-agent that reads or writes repository content.
89+
- **`tools.github.mode: gh-proxy`** — routes GitHub API calls through the gh proxy sidecar; required for the sub-agent to operate on private repositories or to use the GitHub MCP toolset.
90+
91+
```yaml
92+
---
93+
engine: copilot
94+
features:
95+
inline-agents: true
96+
tools:
97+
github:
98+
mode: gh-proxy
99+
cli-proxy: true
100+
---
101+
```
102+
103+
---
104+
105+
## When to Use Sub-Agents
106+
107+
Sub-agents are most useful in two scenarios:
108+
109+
### 1 — Parallel specialised tasks with smaller models
110+
111+
Break a large workflow into parallel units of work, each handled by a small, cheap model, and then use the parent (large) model to reason over the aggregated results:
112+
113+
```markdown
114+
# Investigate: Repository Health
115+
116+
## Step 1 — gather data
117+
118+
Use the `dependency-scanner` agent to list all outdated packages.
119+
Use the `test-coverage` agent to summarise uncovered code paths.
120+
Use the `secret-scanner` agent to check for leaked credentials.
121+
122+
## Step 2 — synthesise
123+
124+
Combine the three reports above into a prioritised action plan.
125+
The top item must have a linked PR draft or issue.
126+
127+
## agent: `dependency-scanner`
128+
---
129+
description: Lists outdated npm/pip/go packages
130+
model: claude-haiku-4.5
131+
---
132+
Run the appropriate package-manager audit command and return a
133+
machine-readable list of outdated packages with their current and
134+
latest versions.
135+
136+
## agent: `test-coverage`
137+
---
138+
description: Summarises low-coverage code paths
139+
model: claude-haiku-4.5
140+
---
141+
Read the most recent test coverage report and list the top 5 files or
142+
functions with coverage below 60 %. Include the file path and line range.
143+
144+
## agent: `secret-scanner`
145+
---
146+
description: Checks for potential credential leaks
147+
model: claude-haiku-4.5
148+
---
149+
Scan staged changes and recently modified files for patterns that
150+
resemble API keys, tokens, or passwords. Report any findings with the
151+
file name and approximate line number.
152+
```
153+
154+
The parent model (e.g. Claude Sonnet or Copilot) orchestrates, while the sub-agents do the heavy lifting with a haiku-size model at lower cost.
155+
156+
### 2 — Reusable specialised helpers
157+
158+
Extract a repetitive sub-task (file summarisation, commit-message generation, code explanation) into a named sub-agent that the main prompt can call by name, keeping the main prompt concise.
159+
160+
---
161+
162+
## Full Example
163+
164+
```markdown
165+
---
166+
engine: copilot
167+
features:
168+
inline-agents: true
169+
tools:
170+
github:
171+
mode: gh-proxy
172+
cli-proxy: true
173+
bash:
174+
- "cat *"
175+
- "ls *"
176+
---
177+
178+
# PR Review Assistant
179+
180+
1. Use the `diff-explainer` agent to produce a plain-English summary of the
181+
diff for PR #${{ github.event.pull_request.number }}.
182+
2. Post the summary as a PR comment.
183+
184+
## agent: `diff-explainer`
185+
---
186+
description: Produces a plain-English summary of a pull request diff
187+
model: claude-haiku-4.5
188+
---
189+
You receive a unified diff. Describe each changed file in one sentence,
190+
focusing on *what changed* and *why it matters*. Ignore formatting-only
191+
changes. Return a bulleted list, one bullet per file.
192+
```
193+
194+
---
195+
196+
## Limitations
197+
198+
- Sub-agents do not support `engine:`, `tools:`, `network:`, or `mcp-servers:` fields — those are stripped at runtime.
199+
- Sub-agents cannot define their own safe-output jobs.
200+
- The feature requires `features.inline-agents: true` — without it the upload/restore steps are not generated.
201+
- Sub-agent blocks must appear in the main workflow file body; they are not resolved inside imported shared files.

.github/workflows/ab-testing-advisor.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/ace-editor.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/agent-performance-analyzer.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/agent-persona-explorer.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/ai-moderator.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/api-consumption-report.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/approach-validator.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/archie.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)