From 8aebaedabe6bb2be2f62fd50f83e5dab848dd965 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Wed, 28 Jan 2026 20:10:17 -0800 Subject: [PATCH] inject plan agent instructions into tool response (#3256) --- .../agents/vscode-node/planAgentProvider.ts | 32 +++++++++++-------- .../tools/vscode-node/switchAgentTool.ts | 11 ++++++- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/extensions/copilot/src/extension/agents/vscode-node/planAgentProvider.ts b/extensions/copilot/src/extension/agents/vscode-node/planAgentProvider.ts index 1b366d891a5..bd78c95a82f 100644 --- a/extensions/copilot/src/extension/agents/vscode-node/planAgentProvider.ts +++ b/extensions/copilot/src/extension/agents/vscode-node/planAgentProvider.ts @@ -206,19 +206,8 @@ export class PlanAgentProvider extends Disposable implements vscode.ChatCustomAg return fileUri; } - private buildCustomizedConfig(): PlanAgentConfig { - const additionalTools = this.configurationService.getConfig(ConfigKey.PlanAgentAdditionalTools); - const modelOverride = this.configurationService.getConfig(ConfigKey.PlanAgentModel); - - // Check askQuestions config first (needed for both tools and body) - const askQuestionsEnabled = this.configurationService.getConfig(ConfigKey.AskQuestionsEnabled); - - // Start with base config, using dynamic body based on askQuestions setting - const config: PlanAgentConfig = { - ...BASE_PLAN_AGENT_CONFIG, - tools: [...BASE_PLAN_AGENT_CONFIG.tools], - handoffs: [...BASE_PLAN_AGENT_CONFIG.handoffs], - body: `You are a PLANNING AGENT, pairing with the user to create a detailed, actionable plan. + static buildAgentBody(askQuestionsEnabled: boolean): string { + return `You are a PLANNING AGENT, pairing with the user to create a detailed, actionable plan. Your job: research the codebase → clarify with the user → produce a comprehensive plan. This iterative approach catches edge cases and non-obvious requirements BEFORE implementation begins. @@ -304,7 +293,22 @@ Rules: - NO code blocks — describe changes, link to files/symbols - NO questions at the end${askQuestionsEnabled ? ' — ask during workflow via #tool:vscode/askQuestions' : ''} - Keep scannable -`, +`; + } + + private buildCustomizedConfig(): PlanAgentConfig { + const additionalTools = this.configurationService.getConfig(ConfigKey.PlanAgentAdditionalTools); + const modelOverride = this.configurationService.getConfig(ConfigKey.PlanAgentModel); + + // Check askQuestions config first (needed for both tools and body) + const askQuestionsEnabled = this.configurationService.getConfig(ConfigKey.AskQuestionsEnabled); + + // Start with base config, using dynamic body based on askQuestions setting + const config: PlanAgentConfig = { + ...BASE_PLAN_AGENT_CONFIG, + tools: [...BASE_PLAN_AGENT_CONFIG.tools], + handoffs: [...BASE_PLAN_AGENT_CONFIG.handoffs], + body: PlanAgentProvider.buildAgentBody(askQuestionsEnabled) }; // Collect tools to add diff --git a/extensions/copilot/src/extension/tools/vscode-node/switchAgentTool.ts b/extensions/copilot/src/extension/tools/vscode-node/switchAgentTool.ts index 5670870574f..c8fc131c83a 100644 --- a/extensions/copilot/src/extension/tools/vscode-node/switchAgentTool.ts +++ b/extensions/copilot/src/extension/tools/vscode-node/switchAgentTool.ts @@ -4,8 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService'; 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'; @@ -16,6 +18,10 @@ interface ISwitchAgentParams { export class SwitchAgentTool implements ICopilotTool { public static readonly toolName = ToolName.SwitchAgent; + constructor( + @IConfigurationService private readonly configurationService: IConfigurationService, + ) { } + async invoke(options: vscode.LanguageModelToolInvocationOptions, token: CancellationToken): Promise { const { agentName } = options.input; @@ -24,6 +30,9 @@ export class SwitchAgentTool implements ICopilotTool { throw new Error(vscode.l10n.t('Only "Plan" agent is supported')); } + const askQuestionsEnabled = this.configurationService.getConfig(ConfigKey.AskQuestionsEnabled); + const planAgentBody = PlanAgentProvider.buildAgentBody(askQuestionsEnabled); + // Execute command to switch agent await vscode.commands.executeCommand('workbench.action.chat.toggleAgentMode', { modeId: agentName, @@ -31,7 +40,7 @@ export class SwitchAgentTool implements ICopilotTool { }); 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.`) + 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}`) ]); }