Repository navigation
chat: custom trajectory compaction model - #316114
Bhavya U (bhavyaus) merged 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds experiment-gated support for routing conversation-history (trajectory) compaction to a dedicated model/endpoint (optionally via the Copilot agentic proxy), shared across both foreground and background compaction paths, and fixes proxy endpoint cloning to preserve proxy routing.
Changes:
- Introduces ExP settings to choose whether compaction uses the agentic proxy and (optionally) a dedicated compaction model.
- Adds a shared
resolveCompactionEndpoint()helper and updates both foreground (summarizedConversationHistory.tsx) and background (agentIntent.ts) compaction call sites to use it and report the effective model in telemetry. - Fixes
ProxyAgenticEndpoint.cloneWithTokenOverride()to return aProxyAgenticEndpoint(preserving proxy routing) and supports a max-prompt-token override.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/platform/endpoint/node/proxyAgenticEndpoint.ts | Preserve agentic-proxy routing when cloning endpoints with a prompt-token override. |
| extensions/copilot/src/platform/configuration/common/configurationService.ts | Adds ExP config keys for compaction endpoint/model selection. |
| extensions/copilot/src/extension/prompts/node/agent/summarizedConversationHistory.tsx | Foreground compaction resolves and uses the dedicated compaction endpoint; telemetry records actual model used. |
| extensions/copilot/src/extension/prompts/node/agent/compactionEndpoint.ts | New helper to resolve the compaction endpoint (proxy vs provider vs fallback). |
| extensions/copilot/src/extension/prompt/node/searchSubagentToolCallingLoop.ts | Updates ProxyAgenticEndpoint instantiation for the new constructor signature. |
| extensions/copilot/src/extension/prompt/node/executionSubagentToolCallingLoop.ts | Updates ProxyAgenticEndpoint instantiation for the new constructor signature. |
| extensions/copilot/src/extension/intents/node/editCodeIntent.ts | Makes endpointProvider protected for use by subclasses. |
| extensions/copilot/src/extension/intents/node/agentIntent.ts | Background compaction resolves and uses the compaction endpoint; tool schemas/capabilities are adjusted based on endpoint choice. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 2
d9b7376 to
6f31254
Compare
|
A couple of design suggestions to shrink the blast radius of this change. The core concern: the off-flag path now runs through the same modified shared helpers, so it's no longer guaranteed to be byte-identical to today. I'd suggest inverting the structure so the flag-off path is physically the original code. 1. Branch instead of intertwine. These are two different algorithms — fork-and-append for cache parity vs. re-render-self-contained — so splitting them keeps the existing path untouched and avoids any unintended changes to it: if (prismEnabled) {
this._startPrismBackgroundSummarization(...); // re-render against compaction endpoint
} else {
this._startBackgroundSummarization(...); // unchanged — exactly today's code
}2. Skip the warm-cache wait on the prism path. The 3. Add a user-visible opt-out. |
eac2d9d to
dfb91af
Compare
|
Flag-off regression: foreground On That matters because stream: options.requestOptions?.stream ?? true,So with the flag off, Anthropic / Messages-API compaction requests now stream where they previously didn't. This breaks the "flag-off is byte-identical to upstream" guarantee we agreed on for the non-forked foreground path. Can we restore |
|
Prism background failure telemetry attributes the wrong model. In Should be |
|
All three addressed:
|
|
Fixed in |
|
Fixed in |
c31b199 to
07f3f67
Compare
…oft#316114) Route conversation-history compaction (foreground /compact and background auto-compaction) to the dedicated trajectory-compaction CAPI model when chat.conversationCompaction.usePrismCompaction is enabled and the agent model matches chat.conversationCompaction.prismModelFilter. When the flag is off, behavior is unchanged from upstream. Squashed rebase of PR microsoft#316114 onto main. Conflicts resolved by unioning additive changes: combined main's isCAPIEndpoint import with the PR's APIUsage import in agentIntent.ts, and kept both main's longToolCallCachePreservation.* and the PR's conversationCompaction.* nls keys. main's microsoft#320273 background-summarization anchor-round fix is preserved (backgroundSummarizer.ts unchanged).
…oft#316114) Route conversation-history compaction (foreground /compact and background auto-compaction) to the dedicated trajectory-compaction CAPI model when chat.conversationCompaction.usePrismCompaction is enabled and the agent model matches chat.conversationCompaction.prismModelFilter. When the flag is off, behavior is unchanged from upstream. Squashed rebase of PR microsoft#316114 onto main. Conflicts resolved by unioning additive changes: combined main's isCAPIEndpoint import with the PR's APIUsage import in agentIntent.ts, and kept both main's longToolCallCachePreservation.* and the PR's conversationCompaction.* nls keys. main's microsoft#320273 background-summarization anchor-round fix is preserved (backgroundSummarizer.ts unchanged).
07f3f67 to
ae3c849
Compare
|
Michael Lively (@Yoyokrazy) pinging here - need help adding Gabe |
Resolved conflicts: - extensions/copilot/src/extension/intents/node/agentIntent.ts: combined main's raceTimeout import with the PR's CancellationError import; dropped stale backgroundTodoProcessor import (renamed/moved on main to backgroundTodoAgent/backgroundTodoAgentProcessor) since BackgroundTodoDecision/BackgroundTodoProcessor/IBackgroundTodoExecutionContext were no longer referenced. - extensions/copilot/src/extension/prompt/vscode-node/endpointProviderImpl.ts: kept the PR's extended JSDoc describing the trajectory-compaction CAPI family fallthrough. Co-authored-by: Copilot <[email protected]>
chat: route conversation-history compaction to the trajectory-compaction CAPI model (
usePrismCompaction)Adds a flag-gated route for conversation-history compaction so we can run summarisation against a dedicated, lighter model instead of the main agent endpoint.
What changes
When
chat.conversationCompaction.usePrismCompactionis enabled and the active agent model matcheschat.conversationCompaction.prismModelFilter, both the foreground (/compact) and background auto-compaction paths resolve their endpoint to thetrajectory-compactionmodel via the standard CAPI endpoint provider (regular chat completions ΓÇö not a separate proxy). When the flag is off, behavior is byte-identical to upstream (the off-flag execution path is physically the original code).Settings
chat.conversationCompaction.usePrismCompaction(ExperimentBased boolean, defaultfalse) ΓÇö master enable flagchat.conversationCompaction.model(ExperimentBased string, default'') ΓÇö when set, overrides the defaulttrajectory-compactionfamilychat.conversationCompaction.prismModelFilter(ExperimentBased string, default'claude-haiku-4.5,claude-sonnet-4.5,claude-sonnet-4.6,gemini-2.5-pro,gemini-3-flash,gemini-3.5-flash') ΓÇö comma-separated, case-insensitive substring filter against the agent model id and family; empty string = no filterAll three settings are registered in
package.json(taggedexperimental+onExp) and have localized descriptions inpackage.nls.json.Routing (
decidePrismRouting)Single source of truth shared by the foreground entry point (
ConversationHistorySummarizer.getSummary) and the background dispatcher inAgentIntentInvocation. Decision order:usePrismCompactionflag off → main agentprismModelFilter→ main agentThe dispatchers then physically branch on the decision: prism requests go through
_getSummaryPrism/_startPrismBackgroundSummarization, and off-flag requests go through the unmodified_getSummary/_startBackgroundSummarizationpaths.Safety nets on the prism path
removedCountduring render; if any node was pruned to fit the compaction endpoint, throwPruningOccurredErrorand fall back to the agent endpoint so the summary sees the full conversation.BudgetExceededErrorand server-sidecontext_length_exceededthrown from_getSummaryPrismalso fall back to the agent endpoint.ChatFetchResponseType.Lengthon the prism path usesresponse.truncatedValueas a partial summary (warn-logged) instead of throwing; only the prism path tolerates this, so off-flag callers continue to fail closed./compact, session dispose, endpoint switch) re-throws without error log or failure telemetry.cacheWarm=trueand skips_lastModelCapabilitiessince the prism endpoint shares no prompt-cache prefix with the main agent loop.Endpoint provider
endpointProvider.getChatEndpoint(family)used to only recognize the utility aliases (copilot-utility,copilot-utility-small); it now falls through togetChatModelFromCapiFamilyfor arbitrary CAPI families sotrajectory-compaction(or any other CAPI-registered family) resolves by name.Diff scope
extension/prompts/node/agent/compactionEndpoint.ts(new)resolveCompactionEndpoint,buildCompactionToolOpts,formatCompactionFailureError,renderCompactionMessages,DEFAULT_COMPACTION_MODEL = 'trajectory-compaction'extension/prompts/node/agent/summarizedConversationHistory.tsxdecidePrismRouting,matchesPrismFilter,PruningOccurredError,_getSummaryPrism,_renderSummarizationPromptWithTracer,_isPromptTooLongError. Off-flag path (_getSummary,_renderSummarizationPrompt,handleSummarizationResponse) is unchanged from pre-PR.extension/intents/node/agentIntent.tsdecidePrismRouting: routes to new_startPrismBackgroundSummarization(re-renders against compaction endpoint, handles Length + cancellation, telemetry usescompactionEndpoint.modelon both success and failure) when prism is on; original_startBackgroundSummarizationis restored byte-for-byte to its pre-PR form.extension/prompt/vscode-node/endpointProviderImpl.tsgetChatEndpointresolves arbitrary CAPI families, not just utility aliasesextension/prompts/node/agent/backgroundSummarizer.tsshouldKickOffBackgroundSummarization+BackgroundSummarizationThresholds, addsendpointIdto the constructor, widens the work-callback return type to… | undefinedplatform/configuration/common/configurationService.tsConfigKeyentriespackage.json+package.nls.jsonextension/prompts/node/agent/test/compactionEndpoint.spec.ts(new)resolveCompactionEndpoint(default, prism-flag-on routing, fallback on resolve failure)Evaluations
Evaluations on MS-Bench summarization bench show using the trajectory compaction model is equivalent or slightly beneficial compared to main agent model trajectory compaction with lower cost. See detailed results and analysis here: Trajectory Compaction Model Proposal
Tests
compactionEndpoint.spec.ts(3),summarization.spec.tsx(34),agentPrompt.spec.tsx(11), andbackgroundSummarizer.spec.ts(23) pass. Net additions from this PR: 3 cases — the newcompactionEndpoint.spec.ts(resolveCompactionEndpoint: default / on-flag / fallback). Other spec files are unchanged from upstream main.Extended dev unit tests for the internal helpers, smoke scripts, and a local-testing doc live on the companion
ryangabriel/custom_trajectory_compaction_model-devbranch for manual end-to-end verification.Manual verification
Set in user settings:
{ "github.copilot.chat.conversationCompaction.usePrismCompaction": true }Reload window, trigger
/compactor let auto-compaction run on a long session. The chat debug log entry'smodelfield should readtrajectory-compactionfor sessions where the agent model matchesprismModelFilter.To narrow which agent models route through prism, override the filter:
{ "github.copilot.chat.conversationCompaction.prismModelFilter": "claude-sonnet-4.6" }Commits (squash-merge recommended)
Initial:
1324b357667route trajectory compaction through CAPI (model: trajectory-compaction)8a32669d44fallow BackgroundSummarizer work callback to resolve undefined86970cfdbb5replace images with text placeholders only when crossing to compaction endpointc2c56e9c0ectrim PR diff per senior-engineer review (renameuseAgenticProxy→usePrismCompaction; moverenderCompactionMessagesintocompactionEndpoint.ts; extract background cross-endpoint branch into a helper)02c4e792ebdtrim non-essential tests, smoke scripts, and docs (dev-only)dfb91afab6aaddress PR review (branch prism path, register settings)Routing, gating, and safety nets:
7c428495db4resolve arbitrary CAPI family in endpointProvider82b7859e93acapacity-gated prism fallback + length/cancellation handlingdd4c4397d2copt prism in per agent model via configurable filterf7e3e032209default prism filter to specific CAPI model IDs32b9385b7e8add gemini-3-flash and gemini-3.5-flash to default prism filter2a2d4f758baapply prism model filter to background path too1dc332e83c9unify prism routing across foreground/background and add debug logs073c7593f95simplify capacity rule in decidePrismRouting922542445fckeep off-flag execution path byte-identical to pre-prism2bc83bae9dehandle Length response on prism foreground pathFollow-up review feedback:
3c403138122address Bhavya review (restorestream: falseon off-flag foreground; attribute prism failure telemetry tocompactionEndpoint.model)008f730b6e4dropcurrentContextTokensprop, rely on post-render pruning checkce0c803abaeclean if/else split between prism and production paths in agentIntent.ts dispatcher66a3cf98f63minimize PR diff + clean prism/production split in summarizedConversationHistory.tsxb0c472e937dtrim verbose comments to minimize PR diff11c9811784elabel prism vs production branches in dispatchersab2a4872467dropstream:falsefrom prism foreground requestc16cf33e63btrim added test cases to minimum needed coverage0a9e6f8751arestore appendTranscriptHintToSummary suite (was preexisting on main)8f39af6fb34revert BackgroundSummarizer.start callback signature widening (use CancellationError on empty render)c31b1997c76restore shouldKickOffBackgroundSummarization test suite (was preexisting on main)