Skip to content

Fix context size handling for Agent Host#322470

Merged
pwang347 merged 21 commits into
mainfrom
pawang/ahpContext
Jun 24, 2026
Merged

Fix context size handling for Agent Host#322470
pwang347 merged 21 commits into
mainfrom
pawang/ahpContext

Conversation

@pwang347

@pwang347 pwang347 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Fixes #321707

Notes:

  • Agent host context in context widget now correctly matches input + output tokens (we were setting output to always 0)
  • Switching models will not also update the context widget, even if it wasn't actually used for the previous request

Dependent on AHP changes:

Copilot AI review requested due to automatic review settings June 22, 2026 22:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes context size handling for Agent Host-backed chat models by representing the selected context window as a first-class ModelSelection.maxContextWindow value (token count) rather than smuggling it through the string-only config bag. It also introduces recommendedContextWindows on models so the chat UI can present a context-size picker consistently across agents, while letting each agent map the numeric selection to its backend representation (e.g. Copilot SDK contextTier).

Changes:

  • Add recommendedContextWindows to model info and maxContextWindow to model selection in the agent-host protocol types, and plumb the new fields through side effects.
  • Synthesize a tokens-group “Context Size” picker from recommendedContextWindows, and lift the selected numeric value into ModelSelection.maxContextWindow when creating sessions.
  • Update Copilot agent/session launching to resolve SDK contextTier from the selected context window, and adjust tests accordingly.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts Adds coverage for lifting context size into maxContextWindow and for synthesizing the picker from recommendedContextWindows.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts Lifts tokens-group numeric config values into ModelSelection.maxContextWindow and includes it in selection equality checks.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostLanguageModelProvider.ts Synthesizes a “Context Size” configuration property from recommendedContextWindows.
src/vs/platform/agentHost/test/node/copilotAgent.test.ts Updates model schema expectations and adds a materialization test for mapping selected context window → SDK tier.
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts Updates model fixtures to include recommendedContextWindows.
src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts Moves contextTier derivation into the agent and threads it through launch plans.
src/vs/platform/agentHost/node/copilot/copilotAgent.ts Exposes recommendedContextWindows, accepts maxContextWindow on selections, and resolves SDK contextTier robustly.
src/vs/platform/agentHost/node/agentSideEffects.ts Plumbs recommendedContextWindows into side-effect output.
src/vs/platform/agentHost/common/state/protocol/channels-root/state.ts Extends protocol state types with recommendedContextWindows and ModelSelection.maxContextWindow.
src/vs/platform/agentHost/common/agentService.ts Extends IAgentModelInfo with recommendedContextWindows.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 3

Comment thread src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts Outdated
Comment thread src/vs/platform/agentHost/common/state/protocol/channels-root/state.ts Outdated
Comment thread src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts
Comment thread src/vs/platform/agentHost/common/state/protocol/.ahp-version Outdated
@pwang347 pwang347 marked this pull request as ready for review June 23, 2026 22:55
sandy081
sandy081 previously approved these changes Jun 23, 2026

@roblourens roblourens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine in general

Comment thread src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts
roblourens
roblourens previously approved these changes Jun 24, 2026
@pwang347 pwang347 dismissed stale reviews from roblourens and sandy081 via ec33661 June 24, 2026 19:58
@pwang347 pwang347 enabled auto-merge (squash) June 24, 2026 19:58
@pwang347 pwang347 disabled auto-merge June 24, 2026 20:41
@pwang347 pwang347 enabled auto-merge (squash) June 24, 2026 21:00
@pwang347 pwang347 merged commit 54f316d into main Jun 24, 2026
45 of 46 checks passed
@pwang347 pwang347 deleted the pawang/ahpContext branch June 24, 2026 21:00
@vs-code-engineering vs-code-engineering Bot added this to the 1.127.0 milestone Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AHP: Context window mismatch between the context size picker and the context usage widget

5 participants