Repository navigation
agentHost: add fork_session server tool - #349426
Draft
Sandeep Somavarapu (sandy081) wants to merge 6 commits into
Draft
Sandeep Somavarapu (sandy081) wants to merge 6 commits into
Sandeep Somavarapu (sandy081) wants to merge 6 commits into
Conversation
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]>
Contributor
There was a problem hiding this comment.
🟡 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]>
Co-authored-by: Copilot <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds a
fork_sessionAgent Host server tool so an agent can fork a chat the way the user's Fork action does.What
An agent can call
fork_sessionto 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 aprompt. The tool is deferred, asks for confirmation, and is offered only to agents that advertisemultipleChats.fork(Copilot, Claude, Codex).Changes
serverToolNames.ts,sessionServerTools.ts: newfork_sessiontool (optionalsession,prompt,title). It goes throughcreateChatwithfork: { source, turnId }, the same path as the UI Fork and AHPcreateChat, so origin, folders and config match. The model follows the UI (activeTurn ?? lastTurn). With apromptit starts the fork with the same delegation metadata ascreate_session.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:createChatpassesforkthrough;supportsChatForksis wired tocapabilities.multipleChats.fork.AGENTS.md: documents the tool.fork_sessionentry (about 21 lines each, 23 in 10 files): the standard tool envelope, the name, one short description that disambiguates it fromcreate_session, and the three parameter descriptions. The eager tool set is unchanged.Notes for reviewers
create_sessionandsend_message. This is intended.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.server tool: fork_session forks the calling chat with its history and runs the prompt: replays on Copilot, Claude and Codex.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.Written by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)