Skip to content

agentHost: add fork_session server tool - #349426

Draft
Sandeep Somavarapu (sandy081) wants to merge 6 commits into
mainfrom
sandy081/agents/fork-session-tool
Draft

Sandeep Somavarapu (sandy081) wants to merge 6 commits into
mainfrom
sandy081/agents/fork-session-tool

Conversation

@sandy081

Copy link
Copy Markdown
Member

Adds a fork_session Agent Host server tool so an agent can fork a chat the way the user's Fork action does.

What

An agent can call fork_session to fork its own chat, or any linked chat, at the last completed turn. The fork is a new nested chat with the copied history, optionally started with a prompt. The tool is deferred, asks for confirmation, and is offered only to agents that advertise multipleChats.fork (Copilot, Claude, Codex).

Changes

  • serverToolNames.ts, sessionServerTools.ts: new fork_session tool (optional session, prompt, title). It goes through createChat with fork: { source, turnId }, the same path as the UI Fork and AHP createChat, so origin, folders and config match. The model follows the UI (activeTurn ?? lastTurn). With a prompt it starts the fork with the same delegation metadata as create_session.
  • It is in sessionConfirmationToolNames, counts against the per-session chat-creation limit (agent orchestration limits), and is refused at call time if the agent cannot fork.
  • agentService.ts, agentServiceFoundation.ts: createChat passes fork through; supportsChatForks is wired to capabilities.multipleChats.fork.
  • AGENTS.md: documents the tool.
  • 19 prompt baselines gain the additive fork_session entry (about 21 lines each, 23 in 10 files): the standard tool envelope, the name, one short description that disambiguates it from create_session, and the three parameter descriptions. The eager tool set is unchanged.

Notes for reviewers

  • Forking a linked chat of another session creates the fork in that session with the caller's credentials, like create_session and send_message. This is intended.
  • No new setting or policy: the tool is covered by session-tool confirmation, the orchestration limits and the fork capability gate. No new UI.
  • Known pre-existing limitation, not changed here: agent host tools, including this one, are not gated by chat.disableAIFeatures. That is tracked separately.

Validation

  • ./scripts/test.sh --glob "vs/platform/agentHost/test/node/**/*.test.js": 15845 passing.
  • ./scripts/test.sh --grep "serverToolGroups deferral budget|toolSearchDeferral": passing.
  • pnpm run typecheck-client: clean.
  • New recorded E2E server tool: fork_session forks the calling chat with its history and runs the prompt: replays on Copilot, Claude and Codex.
  • Live in Code OSS (agent calls fork_session; the fork appears as a nested session with the copied history and runs the prompt): passes; VoiceOver not run; Claude and Codex covered by the E2E replay only.
  • Cross-platform Azure run (definition 727): pending.

Written by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)

Lets an agent fork a chat like the user's Fork action: a new nested session
seeded with the history up to the source's last completed turn, via the host
createChat fork path. The source defaults to the calling chat or is a linked
chat; an optional prompt starts the fork and an optional title names it.
Deferred, confirmation-gated, offered only for agents with multipleChats.fork,
and counted against the chat-creation limit.

Co-authored-by: Copilot <[email protected]>
Fork with the model of the running turn like the UI, label the self case when args are missing, keep the helpers private, drop two token-costing description sentences, and cover the chat-creation limit. Document that forking another session's chat uses the caller's credentials and add a recorded cross-provider E2E test.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 12:13
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.148.0 milestone Nov 20, 2026

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

Active issues include checking the wrong provider’s fork capabilities, losing custom-agent selection on the fork’s first prompted turn, and order-dependent replay matching that can make the new end-to-end test fail.

3 open issues
What changed in this PR

Adds fork_session to Agent Host, allowing agents to branch the current or a linked chat through the existing chat-fork path, optionally starting the fork with a prompt.

Changes:

  • Registers a deferred, confirmation-required tool with capability checks and chat-creation limits.
  • Connects fork options and capability lookup to AgentService and documents the behavior.
  • Adds unit tests, cross-provider replay coverage, and updated model prompt baselines.
File Description
src/​vs/​platform/​agentHost/​test/​node/​sessionServerTools.test.ts Tests fork arguments, history, prompts, limits, and capability checks.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​suites/​serverToolsSuite.ts Adds a fork-and-prompt scenario and capability-aware tool expectations.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​copilotPromptsE2E.integrationTest.ts Adds fork_session to expected host tools.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5.prompt.md Adds the fork tool to the GPT-5 baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5-mini.prompt.md Updates the GPT-5 mini tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5-codex.prompt.md Updates the GPT-5 Codex tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5_6-terra.prompt.md Updates the GPT-5.6 terra tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5_6-sol.prompt.md Updates the GPT-5.6 sol tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5_6-luna.prompt.md Updates the GPT-5.6 luna tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5_1.prompt.md Updates the GPT-5.1 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5_1-codex.prompt.md Updates the GPT-5.1 Codex tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gpt-5_1-codex-mini.prompt.md Updates the GPT-5.1 Codex mini tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_gemini-2_0-flash.prompt.md Updates the Gemini 2.0 Flash tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-sonnet-5.prompt.md Updates the Claude Sonnet 5 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-sonnet-4_6.prompt.md Updates the Claude Sonnet 4.6 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-sonnet-4_5.prompt.md Updates the Claude Sonnet 4.5 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-opus-5.prompt.md Updates the Claude Opus 5 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-opus-5_5.prompt.md Updates the Claude Opus 5.5 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-opus-4_7.prompt.md Updates the Claude Opus 4.7 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-opus-4_6.prompt.md Updates the Claude Opus 4.6 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-opus-4_5.prompt.md Updates the Claude Opus 4.5 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​providers/​__snapshots__/​Agent_Host_E2E___Copilot_prompts_claude-haiku-4_5.prompt.md Updates the Claude Haiku 4.5 tool baseline.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​captures/​copilotcli-server-tool-fork-session-forks-the-calling-chat-with-its-history-and-runs-the-prompt.yaml Records the Copilot fork scenario.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​captures/​codex-server-tool-fork-session-forks-the-calling-chat-with-its-history-and-runs-the-prompt.yaml Records the Codex fork scenario.
src/​vs/​platform/​agentHost/​test/​node/​e2e/​captures/​claude-server-tool-fork-session-forks-the-calling-chat-with-its-history-and-runs-the-prompt.yaml Records Claude tool discovery and forking.
src/​vs/​platform/​agentHost/​node/​shared/​sessionServerTools.ts Implements the tool, validation, confirmation, limits, and display messages.
src/​vs/​platform/​agentHost/​node/​agentServiceFoundation.ts Forwards the fork-capability callback.
src/​vs/​platform/​agentHost/​node/​agentService.ts Passes fork options through and exposes capability lookup.
src/​vs/​platform/​agentHost/​common/​serverToolNames.ts Defines the shared fork_session tool name.
src/​vs/​platform/​agentHost/​AGENTS.md Documents fork semantics and safeguards.

Review effort: Balanced

…session-tool

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
Check fork support with the source chat's provider when chats may use their
own agents, start the fork's first turn with the source's custom agent, and
match the fork E2E replays by content since the fork and its caller can
reach the replay proxy in either order.

Co-authored-by: Copilot <[email protected]>
The adapter dropped the agent of startPrompt and the chat of supportsChatForks, so a fork lost the source's custom agent and was checked against the session's provider. Forward every argument, test the real adapter, and set the fork title only through createChat (the host honors it).

Co-authored-by: Copilot <[email protected]>

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