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;