-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathswitchAgentTool.ts
More file actions
56 lines (44 loc) · 2.46 KB
/
switchAgentTool.ts
File metadata and controls
56 lines (44 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
import { LanguageModelTextPart, LanguageModelToolResult, MarkdownString } from '../../../vscodeTypes';
import { PlanAgentProvider } from '../../agents/vscode-node/planAgentProvider';
import { ToolName } from '../common/toolNames';
import { ICopilotTool, ToolRegistry } from '../common/toolsRegistry';
interface ISwitchAgentParams {
agentName: string;
}
export class SwitchAgentTool implements ICopilotTool<ISwitchAgentParams> {
public static readonly toolName = ToolName.SwitchAgent;
public static readonly nonDeferred = true;
async invoke(options: vscode.LanguageModelToolInvocationOptions<ISwitchAgentParams>, token: CancellationToken): Promise<vscode.LanguageModelToolResult> {
const { agentName } = options.input;
// Only 'Plan' is supported
if (agentName !== 'Plan') {
throw new Error(vscode.l10n.t('Only "Plan" agent is supported'));
}
const planAgentBody = PlanAgentProvider.buildAgentBody(vscode.workspace.getConfiguration('github.copilot.chat').get<boolean>('planAgent.mermaid.enabled', false));
// Execute command to switch agent
await vscode.commands.executeCommand('workbench.action.chat.toggleAgentMode', {
modeId: agentName,
sessionResource: options.chatSessionResource
});
return new LanguageModelToolResult([
new LanguageModelTextPart(`Switched to ${agentName} agent. You are now the ${agentName} agent. This tool may no longer be available in the new agent.\n\n${planAgentBody}`)
]);
}
prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<ISwitchAgentParams>, token: vscode.CancellationToken): vscode.ProviderResult<vscode.PreparedToolInvocation> {
const { agentName } = options.input;
if (agentName !== 'Plan') {
throw new Error(vscode.l10n.t('Only "Plan" agent is supported. Received: "{0}"', agentName));
}
return {
invocationMessage: new MarkdownString(vscode.l10n.t('Switching to {0} agent', agentName)),
pastTenseMessage: new MarkdownString(vscode.l10n.t('Switched to {0} agent', agentName))
};
}
}
ToolRegistry.registerTool(SwitchAgentTool);