Skip to content

Agent Host: add a setting for the runtime's adaptive prompt cache - #350904

Open
Bhavya U (bhavyaus) wants to merge 1 commit into
mainfrom
bhavyaus/prompt-cache-keepalive
Open

Bhavya U (bhavyaus) wants to merge 1 commit into
mainfrom
bhavyaus/prompt-cache-keepalive

Conversation

@bhavyaus

Copy link
Copy Markdown
Collaborator

Adds an opt-in setting, chat.copilot.adaptivePromptCache.enabled (experimental, default off), that turns on the Copilot runtime's adaptive prompt cache for Agent Host Copilot sessions.

When a session using a Claude model sits idle, or waits on a long foreground tool call, for more than 5 minutes, the prompt cache expires and the next request writes the whole conversation into the cache again. The runtime already has an adaptive prompt cache that prevents this. It keeps the cache warm with small background requests, and picks a 1-hour cache lifetime when that is cheaper. It is gated by a runtime experiment that VS Code sessions never receive, because VS Code always supplies its own experiment assignments and the runtime then skips its own experiment lookup.

What changed

  • copilotCliConfig.ts: new root config key adaptivePromptCache and setting ID.
  • chat.shared.contribution.ts: registers the setting. It is boolean, application-scoped, off by default, and tagged experimental and advanced, like the neighbouring Copilot runtime settings.
  • agentHostCopilotCliSettingsContribution.ts: forwards the setting to the agent host.
  • copilotSessionLauncher.ts: when the setting is on, toSdkExpAssignments adds the runtime's adaptive prompt cache arm (ttl_select_refresh_keepalive) to the default config of the session's experiment assignments. This works with or without a VS Code assignment context. When the setting is off, behaviour is unchanged.

The setting applies when a session is created or resumed, the same as chat.copilot.stabilityOrderedPrompt.enabled. An open session picks it up the next time it is reloaded.

How to test

  1. Run Code OSS with "chat.copilot.adaptivePromptCache.enabled": true and use a Claude model in an Agent Host Copilot session.
  2. Build a conversation with a large context, then ask the agent to run sleep 330 in the foreground.
  3. In the runtime log (~/.copilot/logs/process-*.log with chat.agentHost.copilotSdk.logLevel set to trace), an anthropic_prompt_cache_keepalive event with keepalive_kind: ping appears about 4.5 minutes after the last request. The request after the sleep then reads the conversation from the cache instead of writing it again.

My manual run in Code OSS used the same session with a context of about 190k tokens and a 330-second foreground sleep:

Run Keep-alive ping Request after the wait
Setting off for the session none 0 tokens read from cache, 190,485 written
Setting on (after the session reloaded) one ping, 190,610 tokens read from cache 190,610 tokens read from cache, 168 written

The runtime only sends keep-alives once a session is past its warm-up threshold, so a short, fresh session shows no pings.

Validation

  • pnpm run typecheck-client: passed.
  • pnpm run oxlint on the changed files: passed.
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostCopilotCliSettingsContribution.test.ts: passed (289 tests). The new launcher test checks that the arm is assigned on create and resume, with and without an assignment context.
  • Manual end-to-end run in Code OSS, as described above: passed.

Copilot SDK sessions write their whole conversation into the Claude prompt
cache again whenever more than five minutes pass between requests, for example
while a long shell command runs in the foreground or while the user is away.
The runtime has an adaptive prompt cache that picks a 5-minute or 1-hour cache
lifetime per request and keeps the cache warm with small requests while idle,
but VS Code sessions never get it: the runtime skips its own experiment
assignment whenever the host supplies one, and VS Code always does.

Add `chat.copilot.adaptivePromptCache.enabled` (off by default). When it is on,
the experiment assignment VS Code supplies for a created or resumed session
selects the runtime's `ttl_select_refresh_keepalive` arm.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 19:04

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.

🟡 Changes recommended

The adaptive prompt cache opt-in is not forwarded to explicitly connected remote Agent Hosts, leaving new and resumed remote sessions on the default cache behavior.

2 open issues
What changed in this PR

Adds an opt-in setting for the Copilot runtime’s adaptive prompt cache in Agent Host sessions, intended to reduce cache rewrites after idle periods or long tool calls with Claude models.

Changes:

  • Registers an application-scoped, experimental setting that defaults to off.
  • Forwards the setting to the ambient Agent Host and supplies the runtime cache assignment when creating or resuming sessions.
  • Extends tests for settings forwarding and session assignments, including cases without a VS Code assignment context.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostCopilotCliSettingsContribution.test.ts Updates schema fixtures and expected forwarded values.
src/​vs/​workbench/​contrib/​chat/​browser/​chat.shared.contribution.ts Registers the user-facing adaptive-cache setting.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostCopilotCliSettingsContribution.ts Forwards the setting to Agent Host root configuration.
src/​vs/​platform/​agentHost/​test/​node/​copilotSessionLauncher.test.ts Tests cache assignments on session creation and resume.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionLauncher.ts Adds the adaptive-cache arm to runtime experiment assignments.
src/​vs/​platform/​agentHost/​common/​copilotCliConfig.ts Defines the setting ID, root configuration key, and schema.

Review effort: Balanced

description: nls.localize('chat.copilot.adaptivePromptCache.enabled', "When enabled, Copilot SDK sessions using Claude models choose a 5-minute or 1-hour prompt cache lifetime for each request, and keep the cache warm with small background requests while the session is idle or a tool is running. This avoids rewriting the whole conversation into the cache after a pause, at the cost of those background requests. Applies to new and resumed sessions."),
default: false,
tags: ['experimental', 'advanced'],
scope: ConfigurationScope.APPLICATION,
tags: ['experimental', 'advanced'],
scope: ConfigurationScope.APPLICATION,
},
[CopilotAdaptivePromptCacheEnabledSettingId]: {

This branch has not been deployed

No deployments
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.

3 participants