toolInstructions.ts ×6

Frontier kind: Code frontier

unlabeled · c_92bb3e0826ca

453 tests · 3510 LOC · 21 files · introduces 0 tests · 122 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
7 ranges122 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
488 ranges3510 lines · 21 files · Browse complete extent
All tests (intent)
453 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 122 introduced LOC across 7 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/copilot/prompts/toolInstructions.ts 93 introduced LOC · 6 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- toolInstructions.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import type { SectionOverride } from '@github/copilot-sdk';
7 > import { coalesce } from '../../../../../base/common/arrays.js';
8 > import { BrowserChatToolReferenceName, browserChatToolReferenceNames } from '../../../../browserView/common/browserChatToolReferenceNames.js';
9 > import { CLIENT_TOOL_SEARCH_REFERENCE_NAME, RUNTIME_TOOL_SEARCH_TOOL_NAME } from '../../../common/toolSearchConstants.js';
10 >
11 > /**
12 > * Model-agnostic guidance for the `tool_instructions` system-prompt section.
13 > *
14 > * This is the agent-host home for the Copilot extension's `toolUseInstructions`
15 > * pattern (`defaultAgentInstructions.tsx` and the per-model agent prompts): a
16 > * sequence of one-line nudges, each gated on the relevant tool being present in
17 > * the session, composed into the single SDK `tool_instructions` section. The
18 > * agent host sees client tools under their camelCase `toolReferenceName`, so a
19 > * line's gate and any tool name it mentions use that form (NOT the extension's
20 > * snake_case ids).
21 > *
22 > * To add guidance for a tool, write a {@link ToolInstructionLine} and add it to
23 > * {@link TOOL_INSTRUCTION_LINES}. The browser guidance ({@link browserToolInstructions})
24 > * is the first such hookup: it gates on `openBrowserPage` (plus an agentic browser
25 > * tool) being present and returns the extension's "Use the browser tools (...)"
26 > * sentence.
27 > */
28 >
29 > /**
30 > * A single gated tool-instructions line. Returns its content (a single
31 > * sentence, no surrounding newlines) when the session exposes the tools it
32 > * applies to, or `undefined` to contribute nothing. Mirrors one gated `<>…</>`
33 > * fragment in the extension's `toolUseInstructions` block.
34 > *
35 > * @param hasTool predicate for whether a tool name is available in the session.
36 > */
37 > type ToolInstructionLine = (hasTool: (name: string) => boolean) => string | undefined;
38 >
39 > /**
40 > * Browser tools other than `openBrowserPage` — the agent-host equivalent of the
41 > * Copilot extension's `agenticBrowserTools`. Derived from the full reference-name
42 > * list so it stays in sync as browser tools are added or removed.
43 > */
44 > const agenticBrowserToolNames = browserChatToolReferenceNames.filter(name => name !== BrowserChatToolReferenceName.OpenBrowserPage);
45 >
46 > /**
47 > * Front-end guidance for the integrated browser tools, ported from the Copilot
48 > * extension's `defaultAgentInstructions`/per-model prompts. Emitted only when the
49 > * page-opening tool AND at least one agentic browser tool are available, naming
50 > * the first available agentic tool as the example (the rest are covered by "etc.").
51 > */
52 > const browserToolInstructions: ToolInstructionLine = hasTool => {
53 if (!hasTool(BrowserChatToolReferenceName.OpenBrowserPage)) {
54 return undefined;
60 return `Use the browser tools (${BrowserChatToolReferenceName.OpenBrowserPage}, ${companion}, etc.) when beneficial for front-end tasks, such as when visualizing or validating UI changes.`;
61 };
63 > /**
64 > * The registered tool-instruction lines, in render order. Add new per-tool
65 > * guidance here.
66 > */
67 > const TOOL_INSTRUCTION_LINES: readonly ToolInstructionLine[] = [browserToolInstructions];
68 >
69 > /** Tool-search guidance mirrored from the Copilot extension prompt. */
70 > const toolSearchToolInstructions: ToolInstructionLine = hasTool =>
71 hasTool(CLIENT_TOOL_SEARCH_REFERENCE_NAME)
72 ? `Most tools are deferred and hidden until you search for them. Before calling a tool that has not already been loaded, ALWAYS call \`${RUNTIME_TOOL_SEARCH_TOOL_NAME}\` first with a short description of the capability you need, then call the specific tool it returns; tools it returns are immediately available and must not be searched for again.`
73 : undefined;
75 > export function toolSearchInstructionLines(toolSearchActive: boolean): readonly ToolInstructionLine[] {
76 return toolSearchActive ? [...TOOL_INSTRUCTION_LINES, toolSearchToolInstructions] : TOOL_INSTRUCTION_LINES;
77 }
79 > /**
80 > * Composes the applicable `lines` into a single block (one line each), or
81 > * `undefined` when none apply to the session.
82 > *
83 > * @param lines defaults to the registered {@link TOOL_INSTRUCTION_LINES};
84 > * overridable so the composition can be exercised in isolation.
85 > */
86 > export function universalToolInstructions(hasTool: (name: string) => boolean, lines: readonly ToolInstructionLine[] = TOOL_INSTRUCTION_LINES): string | undefined {
87 const rendered = coalesce(lines.map(line => line(hasTool)));
88 return rendered.length > 0 ? rendered.join('\n') : undefined;
89 }
91 > /**
92 > * Folds universal tool-instructions `content` into a per-model contributor's
93 > * `existing` `tool_instructions` override (if any), so a contributor's section
94 > * is preserved rather than clobbered.
95 > *
96 > * @param existing the per-model contributor's `tool_instructions` override, if any.
97 > */
98 function composeToolInstructions(existing: SectionOverride | undefined, content: string): SectionOverride {
99 // No per-model override: append after the SDK foundation section, led by a
120 }
121 }
123 > /**
124 > * Resolves the `tool_instructions` {@link SectionOverride} for a session,
125 > * composing the universal lines with any override a per-model contributor
126 > * already set for that section.
127 > *
128 > * Returns `undefined` when no universal lines apply — the caller then keeps the
129 > * contributor's `existing` override (if any) untouched.
130 > *
131 > * @param existing the per-model contributor's `tool_instructions` override, if any.
132 > * @param lines defaults to the registered {@link TOOL_INSTRUCTION_LINES}.
133 > */
134 > export function resolveToolInstructionsOverride(hasTool: (name: string) => boolean, existing: SectionOverride | undefined, lines: readonly ToolInstructionLine[] = TOOL_INSTRUCTION_LINES): SectionOverride | undefined {
135 const content = universalToolInstructions(hasTool, lines);
136 return content === undefined ? undefined : composeToolInstructions(existing, content);
src/vs/platform/browserView/common/browserChatToolReferenceNames.ts 29 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- browserChatToolReferenceNames.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > /**
7 > * Tool reference names for the integrated browser tools.
8 > *
9 > * Lives in `platform` (rather than next to the `workbench/contrib/browserView`
10 > * tools that produce them) so the Copilot agent host — which cannot import from
11 > * `workbench` — can gate its browser tool instructions on the same names.
12 > */
13 > export const BrowserChatToolReferenceName = {
14 > OpenBrowserPage: 'openBrowserPage',
15 > ReadPage: 'readPage',
16 > ScreenshotPage: 'screenshotPage',
17 > NavigatePage: 'navigatePage',
18 > ClickElement: 'clickElement',
19 > TypeInPage: 'typeInPage',
20 > HoverElement: 'hoverElement',
21 > DragElement: 'dragElement',
22 > HandleDialog: 'handleDialog',
23 > RunPlaywrightCode: 'runPlaywrightCode',
24 > } as const;
25 >
26 > /**
27 > * All browser-tool reference names as a flat list.
28 > */
29 > export const browserChatToolReferenceNames = Object.values(BrowserChatToolReferenceName);