豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 1a089d9

Browse files
authored
add isSystemInitiated and relevant changes (#4944)
* add isSystemInitiated and relevant changes * simplify agent interaction type determination and add utility function for request kind mapping * update proposed api * resolve issue * Address feedback * update * revert unrelated changes * revert changes * fix tests
1 parent e656fc9 commit 1a089d9

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

src/extension/intents/node/toolCallingLoop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
12851285
type: 'function',
12861286
})),
12871287
},
1288-
userInitiatedRequest: (iterationNumber === 0 && !isContinuation && !this.options.request.subAgentInvocationId) || this.stopHookUserInitiated,
1288+
userInitiatedRequest: (iterationNumber === 0 && !isContinuation && !this.options.request.subAgentInvocationId && !this.options.request.isSystemInitiated) || this.stopHookUserInitiated,
12891289
enableThinking,
12901290
reasoningEffort,
12911291
}, token).finally(() => {

src/extension/prompt/node/chatParticipantTelemetry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ type RequestPanelTelemetryProperties = RequestTelemetryProperties & {
152152
parentRequestId: string | undefined;
153153
vscodeRequestId: string | undefined;
154154
slashCommand: string;
155+
isSystemInitiated: string;
155156
};
156157

157158
type RequestTelemetryMeasurements = {
@@ -717,7 +718,8 @@ export class PanelChatTelemetry extends ChatTelemetry<IDocumentContext | undefin
717718
"mode": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The chat mode used for this request (e.g., ask, edit, agent, custom)." },
718719
"parentRequestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The parent request id if this request is from a subagent." },
719720
"vscodeRequestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The VS Code chat request id, for joining with VS Code telemetry events." },
720-
"slashCommand": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The slash command used by the user, if any (e.g. troubleshoot, explain). Empty if no slash command was used." }
721+
"slashCommand": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The slash command used by the user, if any (e.g. troubleshoot, explain). Empty if no slash command was used." },
722+
"isSystemInitiated": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether the request was system-initiated (e.g. terminal completion notification) rather than user-typed." }
721723
}
722724
*/
723725
this._telemetryService.sendMSFTTelemetryEvent('panel.request', {
@@ -737,7 +739,8 @@ export class PanelChatTelemetry extends ChatTelemetry<IDocumentContext | undefin
737739
mode: this._getModeNameForTelemetry(),
738740
parentRequestId: this._request.parentRequestId,
739741
vscodeRequestId: this._request.id,
740-
slashCommand: getSlashCommandForTelemetry(this._request, URI.from(this._extensionContext.extensionUri))
742+
slashCommand: getSlashCommandForTelemetry(this._request, URI.from(this._extensionContext.extensionUri)),
743+
isSystemInitiated: String(!!this._request.isSystemInitiated)
741744
} satisfies RequestPanelTelemetryProperties, {
742745
turn: this._conversation.turns.length,
743746
round: roundIndex,

src/extension/prompt/node/defaultIntentRequestHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class DefaultToolCallingLoop extends ToolCallingLoop<IDefaultToolLoopOptions> {
718718
messageId: this.telemetry.telemetryMessageId,
719719
conversationId: this.options.conversation.sessionId,
720720
messageSource: this.options.intent?.id && this.options.intent.id !== UnknownIntent.ID ? `${messageSourcePrefix}.${this.options.intent.id}` : `${messageSourcePrefix}.user`,
721-
subType: this.options.request.subAgentInvocationId ? `subagent` : undefined,
721+
subType: this.options.request.subAgentInvocationId ? `subagent` : this.options.request.isSystemInitiated ? 'system-initiated' : undefined,
722722
parentRequestId: this.options.request.parentRequestId,
723723
},
724724
requestKindOptions: this.options.request.subAgentInvocationId

src/extension/prompt/node/test/__snapshots__/defaultIntentRequestHandler.spec.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
670670
"contextTypes": "none",
671671
"conversationId": "some-session-id",
672672
"isParticipantDetected": "false",
673+
"isSystemInitiated": "false",
673674
"languageId": undefined,
674675
"mode": "ask",
675676
"model": "gpt-4.1-2025-04-14",
@@ -911,6 +912,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
911912
"contextTypes": "none",
912913
"conversationId": "some-session-id",
913914
"isParticipantDetected": "false",
915+
"isSystemInitiated": "false",
914916
"languageId": undefined,
915917
"mode": "ask",
916918
"model": "gpt-4.1-2025-04-14",
@@ -1152,6 +1154,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
11521154
"contextTypes": "none",
11531155
"conversationId": "some-session-id",
11541156
"isParticipantDetected": "false",
1157+
"isSystemInitiated": "false",
11551158
"languageId": undefined,
11561159
"mode": "ask",
11571160
"model": "gpt-4.1-2025-04-14",
@@ -1393,6 +1396,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
13931396
"contextTypes": "none",
13941397
"conversationId": "some-session-id",
13951398
"isParticipantDetected": "false",
1399+
"isSystemInitiated": "false",
13961400
"languageId": undefined,
13971401
"mode": "ask",
13981402
"model": "gpt-4.1-2025-04-14",
@@ -1684,6 +1688,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
16841688
"contextTypes": "none",
16851689
"conversationId": "some-session-id",
16861690
"isParticipantDetected": "false",
1691+
"isSystemInitiated": "false",
16871692
"languageId": undefined,
16881693
"mode": "ask",
16891694
"model": "gpt-4.1-2025-04-14",
@@ -1925,6 +1930,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
19251930
"contextTypes": "none",
19261931
"conversationId": "some-session-id",
19271932
"isParticipantDetected": "false",
1933+
"isSystemInitiated": "false",
19281934
"languageId": undefined,
19291935
"mode": "ask",
19301936
"model": "gpt-4.1-2025-04-14",
@@ -2166,6 +2172,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
21662172
"contextTypes": "none",
21672173
"conversationId": "some-session-id",
21682174
"isParticipantDetected": "false",
2175+
"isSystemInitiated": "false",
21692176
"languageId": undefined,
21702177
"mode": "ask",
21712178
"model": "gpt-4.1-2025-04-14",
@@ -2407,6 +2414,7 @@ exports[`defaultIntentRequestHandler > confirms on max tool call iterations, and
24072414
"contextTypes": "none",
24082415
"conversationId": "some-session-id",
24092416
"isParticipantDetected": "false",
2417+
"isSystemInitiated": "false",
24102418
"languageId": undefined,
24112419
"mode": "ask",
24122420
"model": "gpt-4.1-2025-04-14",
@@ -2731,6 +2739,7 @@ exports[`defaultIntentRequestHandler > makes a successful request with a single
27312739
"contextTypes": "none",
27322740
"conversationId": "some-session-id",
27332741
"isParticipantDetected": "false",
2742+
"isSystemInitiated": "false",
27342743
"languageId": undefined,
27352744
"mode": "ask",
27362745
"model": "gpt-4.1-2025-04-14",
@@ -3082,6 +3091,7 @@ exports[`defaultIntentRequestHandler > makes a tool call turn 2`] = `
30823091
"contextTypes": "none",
30833092
"conversationId": "some-session-id",
30843093
"isParticipantDetected": "false",
3094+
"isSystemInitiated": "false",
30853095
"languageId": undefined,
30863096
"mode": "ask",
30873097
"model": "gpt-4.1-2025-04-14",
@@ -3323,6 +3333,7 @@ exports[`defaultIntentRequestHandler > makes a tool call turn 2`] = `
33233333
"contextTypes": "none",
33243334
"conversationId": "some-session-id",
33253335
"isParticipantDetected": "false",
3336+
"isSystemInitiated": "false",
33263337
"languageId": undefined,
33273338
"mode": "ask",
33283339
"model": "gpt-4.1-2025-04-14",

src/extension/prompts/node/agent/agentPrompt.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ export interface AgentUserMessageProps extends BasePromptElementProps, AgentUser
305305
readonly hasStopHookQuery?: boolean;
306306
/** Additional context provided by SubagentStart hooks. */
307307
readonly additionalHookContext?: string;
308+
/** When true, this request was system-initiated (e.g. terminal completion notification) and should skip context/wrapping. */
309+
readonly isSystemInitiated?: boolean;
308310
}
309311

310312
export function getUserMessagePropsFromTurn(turn: Turn, endpoint: IChatEndpoint, customizations?: AgentUserMessageCustomizations): AgentUserMessageProps {
@@ -334,6 +336,7 @@ export function getUserMessagePropsFromAgentProps(agentProps: AgentPromptProps,
334336
editedFileEvents: agentProps.promptContext.editedFileEvents,
335337
hasStopHookQuery: agentProps.promptContext.hasStopHookQuery,
336338
additionalHookContext: agentProps.promptContext.additionalHookContext,
339+
isSystemInitiated: agentProps.promptContext.request?.isSystemInitiated,
337340
// TODO:@roblourens
338341
sessionId: (agentProps.promptContext.tools?.toolInvocationToken as any)?.sessionId,
339342
sessionResource: (agentProps.promptContext.tools?.toolInvocationToken as any)?.sessionResource,
@@ -365,6 +368,12 @@ export class AgentUserMessage extends PromptElement<AgentUserMessageProps> {
365368
this.logService.trace('Re-rendering historical user message');
366369
}
367370

371+
// System-initiated messages (e.g. terminal completion notifications) are
372+
// self-contained and should not be wrapped in <userRequest> or have context re-added.
373+
if (this.props.isSystemInitiated) {
374+
return <UserMessage>{this.props.request}</UserMessage>;
375+
}
376+
368377
const query = await this.promptVariablesService.resolveToolReferencesInPrompt(this.props.request, this.props.toolReferences ?? []);
369378
const hasReplaceStringTool = !!this.props.availableTools?.find(tool => tool.name === ToolName.ReplaceString);
370379
const hasMultiReplaceStringTool = !!this.props.availableTools?.find(tool => tool.name === ToolName.MultiReplaceString);

0 commit comments

Comments
 (0)