AGENTS.md
src/vs/platform/agentHost/node/copilot/prompts/AGENTS.mdAGENTS.md
Quality
58/100
Scores the file, not the repository.Length
1,184 words
8 headings · 2 code blocksRepository
188k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Agent host system-prompt customization23This directory customizes the system prompt for Copilot CLI **agent host**4(ahp+cli) sessions. Read this before changing how the system message is built or5adding per-model / per-tool guidance. It mirrors the Copilot extension's6`extensions/copilot/.../prompts/node/agent/` (agentPrompts), but the agent host7runs in its own process and cannot use prompt-tsx, so contributors return plain8data the SDK accepts directly.910## Files1112- `promptRegistry.ts` — `AgentHostPromptRegistry`: resolves the final13 `SystemMessageConfig` for a session's model. Defines the `IAgentHostPrompt`14 contributor interface and the `IAgentHostPromptContext` read-time context.15- `systemMessage.ts` — the default message (`COPILOT_AGENT_HOST_SYSTEM_MESSAGE`),16 shared identity text, the `fullSystemPrompt` / `sectionOverrides` builders, and17 `describeSystemMessageConfig` (the one-line log summary).18- `toolInstructions.ts` — the model-agnostic `tool_instructions` layer: gated19 one-line nudges (`TOOL_INSTRUCTION_LINES`) composed into the SDK's20 `tool_instructions` section. The browser line is the one registered today.21- `anthropicPrompt.ts` — example per-model contributor (Claude Opus 4.8).22- `allPrompts.ts` — side-effect import hub; importing it registers every23 contributor into the shared `agentHostPromptRegistry`.2425## How the system message is built2627`resolveSystemMessageConfig(model, context)` runs two steps:28291. **`_resolveModelConfig`** — picks the per-model (or default) config. Falls30 back to `COPILOT_AGENT_HOST_SYSTEM_MESSAGE` when there's no model, no matching31 contributor, or the contributor opts out for this `context`.322. **`_withUniversalSections`** — layers the model-agnostic sections (currently33 just `tool_instructions`) on top, **composing** with — never clobbering — any34 per-model override for that section.3536> **Launch-time freeze.** The SDK accepts a system message only at session37> create/resume; there is no mid-session update. The prompt is resolved once per38> (re)launch and any tool-gated content reflects the tool set at that moment. A39> change to the session's tools/plugins is part of the launcher's restart40> snapshot, so it re-launches and recomputes; an in-flight turn keeps the prompt41> it launched with.4243There are two ways to customize, and a model can use both at once.4445## Lever 1 — universal, all models (`toolInstructions.ts`)4647Guidance for a tool that should apply to **every** model whenever that tool is in48the session. This is what the browser line does.49501. Write a `ToolInstructionLine` — a function `(hasTool) => string | undefined`51 that returns one sentence (no surrounding newlines) when its tool is present,52 or `undefined` to contribute nothing.532. Add it to `TOOL_INSTRUCTION_LINES`.5455```ts56const exampleToolInstructions: ToolInstructionLine = hasTool =>57 hasTool('someClientToolReferenceName')58 ? 'One sentence of guidance, shown only when that tool is present.'59 : undefined;6061const TOOL_INSTRUCTION_LINES: readonly ToolInstructionLine[] = [browserToolInstructions, exampleToolInstructions];62```6364**Caveat — `hasTool` sees CLIENT tools only.** It is `context.hasClientTool`,65which knows only the forwarded workbench tools, addressed by their **camelCase66`toolReferenceName`** (e.g. `openBrowserPage`, `runTask`, `getTaskOutput`) — NOT67the extension's snake_case ids, and NOT shell / server-SDK / MCP tools (MCP is68discovered dynamically and isn't in the launch snapshot). A69line gated on a name that is never a client tool silently never renders. The70default client-tool allowlist is `chat.agentHost.clientTools` (see71`chat.shared.contribution.ts`). Broadening this context is a known follow-up.7273These lines compose with a per-model `tool_instructions` override (see74`composeToolInstructions`), so Lever 1 and Lever 2 stack.7576## Tool search (deferred tool loading)7778When `chat.agentHost.copilot.toolSearch.enabled` is on AND the session's model79supports it (`agentHostModelSupportsToolSearch`), the launcher sets80`toolSearch: { enabled: true, deferThreshold: 1 }` and the session defers MCP +81non-core client tools behind the runtime's `tool_search_tool`:8283- **The override** (`copilotAgentSession._createClientSdkTools`): the client's84 forwarded `toolSearch` tool is registered as `tool_search_tool` with85 `overridesBuiltInTool: true` and `defer: 'never'`, so the runtime routes the86 model's search to the client's semantic search. The SDK supplies the runtime's87 live deferred-tool metadata to the override handler; Agent Host carries that88 corpus as transient tool-call metadata and injects it only into the local89 `toolSearch` invocation, so embeddings rank the runtime/MCP tools rather than90 the extension's registry. The corpus is never added to model-facing tool input.91 Every other client tool gets92 `defer: 'never'` if it is in `NON_DEFERRED_CLIENT_TOOL_NAMES`93 (`runTests`, `rename`, `usages`), else `defer: 'auto'`. Built-in runtime tools94 are never deferred. The renderer (`agentHostSessionHandler._setupClientToolCall`)95 maps `tool_search_tool` back to `toolSearch` to execute the real VS Code tool.96- **The prompt** (this folder): `toolSearchInstructionLines(toolSearchActive)`97 adds a `tool_instructions` line (`toolSearchToolInstructions`) telling the98 model to load deferred tools via `tool_search_tool` first — gated on99 `context.toolSearchActive` because the `toolSearch` tool is *always* forwarded,100 so presence alone can't gate it. The runtime already emits its own101 deferred-tools reminder (`build_deferred_tools_user_message`) with the accurate102 deferred set, so this layer intentionally does NOT re-list the deferred tools.103104The two identity/count levers are independent: `deferThreshold` is a total105tool-count gate (1 ⇒ always active), while each tool's `defer` flag decides106whether *that* tool is deferred.107108This B-inject bridge is intentionally interim. A follow-up moves tool-search109registration and ranking into VS Code core so Agent Host no longer depends on110the Copilot extension's tool implementation or embeddings plumbing.111112## Lever 2 — per-model contributor (`promptRegistry.ts` + `allPrompts.ts`)113114Guidance scoped to a model or family. Implement `IAgentHostPrompt` and register115it. Use `anthropicPrompt.ts` as the template.116117A contributor provides EITHER:118119- `resolveSectionOverrides` → `{ mode: 'customize' }` — overrides named sections,120 keeps the SDK foundation prompt and its guardrails. **Prefer this.**121- `resolveFullSystemPrompt` → `{ mode: 'replace' }` — owns the entire prompt and122 **drops all SDK guardrails (including safety)**. Only for callers that truly123 own the whole prompt. A replace contributor bypasses Lever 1, so it must inline124 any universal guidance itself (`universalToolInstructions(hasTool)` renders the125 same gated lines; add a small replace-mode helper alongside it when the first126 such contributor lands).127128```ts129class MyModelPrompt implements IAgentHostPrompt {130 static readonly familyPrefixes = ['my-model']; // or implement static matchesModel(model)131 resolveSectionOverrides(model: ModelSelection, context: IAgentHostPromptContext) {132 // Gate on host settings; return undefined to fall back to the default message.133 return context.getSetting(CopilotCliConfigKey.SomeFlag) === true134 ? { tool_instructions: { action: 'append', content: '\nFor this model, batch independent tool calls.' } }135 : undefined;136 }137}138agentHostPromptRegistry.registerPrompt(MyModelPrompt); // then add `import './myModelPrompt.js'` to allPrompts.ts139```140141Matching: a contributor matches a model by `static matchesModel(model)` (takes142precedence) or by `familyPrefixes` (model-id `startsWith`). The registry resolves143**exactly one** contributor per model (first match wins) — base + version144layering is a known follow-up.145146## Reference147148- **Modes** (`SystemMessageConfig.mode`): `append` (foundation + text, default),149 `customize` (override named sections), `replace` (own the whole prompt, no150 guardrails).151- **Sections** (`SystemMessageSection`): `identity`, `tone`, `tool_efficiency`,152 `environment_context`, `code_change_rules`, `guidelines`, `safety`,153 `tool_instructions`, `custom_instructions`, `runtime_instructions`,154 `last_instructions`.155- **Override actions** (`SectionOverride.action`): `replace`, `append`,156 `prepend`, `remove`, or a `(content: string) => string` transform.157158## Gotchas159160- **Empty overrides = no override.** `resolveSectionOverrides` returning `{}`161 (or `undefined`) falls back to the default message rather than emitting an162 empty customize config that would drop the default identity.163- **Don't mutate the shared default.** `COPILOT_AGENT_HOST_SYSTEM_MESSAGE` is a164 shared constant; layering spreads into a fresh object, preserving any other165 customize-mode fields (e.g. `content`). Keep it that way.166- **Spacing is relative to the foundation.** `composeToolInstructions` pads by167 action (`append` leads with `\n`, `prepend` trails with `\n`, `replace` owns168 the section). When writing a section's `content` by hand, a leading `\n` keeps169 appended text off the foundation's last line.170- **Observability.** The launcher logs `describeSystemMessageConfig(...)` at171 `info` (mode + overridden sections) and the full config at `trace`. Keep new172 config shapes summarizable there.173- **Tests.** `../../../test/node/agentHostPromptRegistry.test.ts` covers the174 registry/wiring; `../../../test/node/toolInstructions.test.ts` covers the175 composition/gating. Add cases there, not new harnesses.176
Also in microsoft/vscode
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| microsoft/vscode.github/instructions/accessibility.instructions.md · 188k | Copilot instructions | styledo-not | 61/100 | 3 days ago | |
| microsoft/vscode.github/instructions/chat.instructions.md · 188k | Copilot instructions | no sections | 39/100 | 3 days ago | |
| microsoft/vscodeextensions/copilot/src/platform/authentication/common/AGENTS.md · 188k | AGENTS.md | archsecurityagent-behaviour | 58/100 | 3 days ago | |
| microsoft/vscode.github/copilot-instructions.md · 188k | Copilot instructions | stylearchtypesui+2 | 74/100 | 2 days ago | |
| microsoft/vscode.github/instructions/agentHostTesting.instructions.md · 188k | Copilot instructions | teststyletesting-strategyagent-behaviour | 55/100 | 3 days ago | |
| microsoft/vscode.github/instructions/ai-customization.instructions.md · 188k | Copilot instructions | archtypesui | 58/100 | 3 days ago | |
| microsoft/vscode.github/instructions/best-practices.instructions.md · 188k | Copilot instructions | styleui | 60/100 | 3 days ago | |
| microsoft/vscode.github/instructions/buildNext.instructions.md · 188k | Copilot instructions | setupbuildtestarch+1 | 66/100 | 3 days ago | |
| microsoft/vscode.github/instructions/coding-guidelines.instructions.md · 188k | Copilot instructions | styletypesuidocs | 60/100 | 3 days ago | |
| microsoft/vscode.github/instructions/committing.instructions.md · 188k | Copilot instructions | do-not | 23/100 | 3 days ago | |
| microsoft/vscode.github/instructions/css-best-practices.instructions.md · 188k | Copilot instructions | styleui | 29/100 | 3 days ago | |
| microsoft/vscode.github/instructions/design-philosophy.instructions.md · 188k | Copilot instructions | style | 34/100 | 3 days ago | |
| microsoft/vscode.github/instructions/design-tokens.instructions.md · 188k | Copilot instructions | styledo-not | 65/100 | 3 days ago | |
| microsoft/vscode.github/instructions/disposable.instructions.md · 188k | Copilot instructions | no sections | 16/100 | 3 days ago | |
| microsoft/vscode.github/instructions/interactive.instructions.md · 188k | Copilot instructions | ui | 43/100 | 3 days ago | |
| microsoft/vscode.github/instructions/kusto.instructions.md · 188k | Copilot instructions | agent-behaviour | 16/100 | 3 days ago | |
| microsoft/vscode.github/instructions/learnings.instructions.md · 188k | Copilot instructions | style | 40/100 | 3 days ago | |
| microsoft/vscode.github/instructions/notebook.instructions.md · 188k | Copilot instructions | no sections | 48/100 | 3 days ago | |
| microsoft/vscode.github/instructions/observables.instructions.md · 188k | Copilot instructions | no sections | 40/100 | 3 days ago | |
| microsoft/vscode.github/instructions/oss-third-party-notices.instructions.md · 188k | Copilot instructions | buildgitdependenciesdeployment+1 | 65/100 | 3 days ago |
Diff against .github/instructions/accessibility.instructions.md Diff against .github/instructions/chat.instructions.md Diff against extensions/copilot/src/platform/authentication/common/AGENTS.md Diff against .github/copilot-instructions.md Diff against .github/instructions/agentHostTesting.instructions.md Diff against .github/instructions/ai-customization.instructions.md Diff against .github/instructions/best-practices.instructions.md Diff against .github/instructions/buildNext.instructions.md Diff against .github/instructions/coding-guidelines.instructions.md Diff against .github/instructions/committing.instructions.md Diff against .github/instructions/css-best-practices.instructions.md Diff against .github/instructions/design-philosophy.instructions.md Diff against .github/instructions/design-tokens.instructions.md Diff against .github/instructions/disposable.instructions.md Diff against .github/instructions/interactive.instructions.md Diff against .github/instructions/kusto.instructions.md Diff against .github/instructions/learnings.instructions.md Diff against .github/instructions/notebook.instructions.md Diff against .github/instructions/observables.instructions.md Diff against .github/instructions/oss-third-party-notices.instructions.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| wpscanteam/wpscanAGENTS.md · 9.7k | AGENTS.md | setupbuildteststyle+6 | 100/100 | 2 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago |
