dsh-agent-preset-branch: Branching Sessions by New Mode on Completed Rounds

Introduction

In DeepSeek Harness (DSH), Agent presets determine how the tool layer and prompt sections are assembled. Once a session has run at least one turn, the host locks the mode: agent-preset-registry’s select() throws agent-preset/locked when openTurnStartSeq !== null || lastTurn > 0. The product’s built-in fork can only inherit the parent session’s mode—SessionForkRequest only contains { sessionId, atSeq }, with no agentPreset field.

A common requirement in actual development is: after a conversation has run for several turns, you want to switch to another set of Agent presets like “Planning” or “Reviewing” to continue, rather than forcing a conversation within the old mode. Below is an introduction to the community plugin dsh-agent-preset-branch (maintainer lanhui1942). It bridges the gap of “switching mode + retaining context” by using “new session + migrating event log prefix” instead of performing a fork.

What is this

dsh-agent-preset-branch is a DSH workflow-class plugin (GitHub: lanhui1942/dsh-agent-preset-branch, current package version 1.1.0, MIT License). In one sentence: it branches a session into a new mode from any completed turn—select an Agent preset, and it creates a new session with that mode, and migrates the conversation from the current session up to the end of the selected turn to it; the migration copies the event log (not a summary), and does not modify the source session.

The difference from its predecessor dsh-agent-preset-select is: for tasks that have already started, the former only creates a new empty session with that mode, while this plugin creates a new one and carries the existing conversation; for tasks that haven’t started, both switch modes in place.

Why you cannot rely solely on forking or post-hoc mode changes

Two structural constraints of DSH block “forking first, then changing mode”:

  1. The mode is locked after the first turn, and lastTurn does not roll back.
  2. The forked child session is assembled using presetForObservation(source), inevitably inheriting the parent mode; even if you fork first and then switch mode, it will still be rejected by rule 1.

Therefore, the mode must be settled at the exact moment of session assembly, and the content is handed to that session.create as a seed. The host already has session.create({ agentPreset }); what is missing is feeding the conversation into it—this plugin combines the two steps into a single call.

Core Features

Two Entry Points, One Engine

Entry Point Mount Location Interaction
Header Mode Menu The agent-preset slot in conversation.session.header.actions Select mode first, then click submit at the bottom of the card; switches in place for sessions that haven’t started
“Branch Mode” Capsule at Turn Bottom branch-mode in conversation.chat.assistant-actions, right next to the built-in fork button Expands a list of modes, clicking a mode immediately creates a branched session, no second step
  • No turns run yet: The bottom of the header shows “Switch to ‘[Mode Name]’”, taking the registry’s official switch path.
  • At least one turn completed: The header shows “New Session with ‘[Mode Name]’”; each completed assistant message row at the bottom of the turn has a capsule, with the cut-off point being that turn’s turn/end (atSeq). Historical turns and the last turn share the same routing, only the cut-off point differs.
  • This plugin does not perform fork; it sits alongside the product’s built-in fork button and does not replace existing slots like copy or feedback.

Host-side Migration Sequence (Overview)

The sequence in core.js (unit testable):

  1. agentPresets.resolve(targetMode) — If the mode is invalid, no half-baked session is left behind.
  2. sessionQuery.observeSession(sourceSession) — Read-only lease to read the header and full event log; the source session is not written to.
  3. Calculate cut-off point: default is the end of the last completed turn; atSeq is optional and must correspond to some turn/end, otherwise it falls back to default and notes the actual cut-off point in the response. If there are no completed turns, it rejects and prompts to finish a turn first.
  4. buildForkSeed(events, cut-off point) — Copies the prefix and marks it as inherited (dynamically loads host implementation, has a local fallback if parsing fails).
  5. A single ctx.agents.create: carries seed, inheritedEventCount, meta (including parentSession, isSeeded, agentPreset), reuses the source session model’s agentOptions, and agentPresets.mount in setup — assembled with the selected mode then published, not published then switched.
  6. Mount the new session to the Workspace where the source session resides (subagent traces lineage upwards), and try to reuse the original title.

HTTP Routes

The route name branch is retained for historical reasons, but the behavior is “create new and migrate”:

GET  /dsh-agent-preset-branch/list      Optional mode roster + default mode
GET  /dsh-agent-preset-branch/inspect   ?sessionId=…  Recorded mode vs actually composed mode
POST /dsh-agent-preset-branch/branch    { sessionId, agentPreset, title?, atSeq? }
POST /dsh-agent-preset-branch/switch    { sessionId, agentPreset }  (Only for sessions that haven't started)

inspect is used to troubleshoot “created but mode looks unchanged”: compare recordedPreset with composedPreset.

Installation and Enablement

The plugin is loaded with DSH via profiles; after installation, DSH needs to be restarted (browser-side bundles can hot-update, but host.js / core.js will not). Please read the repository source code and MIT license yourself before installing; the plugin runs under the current dsh process permissions.

Three installation methods (choose one):

1. From tarball (recommended for external distribution):

dsh plugin --profile <profile> add <absolute path to dsh-agent-preset-branch-1.1.0.tgz>

You can also paste the same .tgz path in the “Settings → Plugins” installation box.

2. Point to the plugin directory:

dsh plugin --profile <profile> add <absolute path to this directory>

3. Manual link dependency: In the profile’s package.json:

"dsh-agent-preset-branch": "link:<absolute path to this directory>"

And add it to dsh.profile.bundles, then restart DSH. You must use link: instead of a version number, otherwise pnpm will look for the package in the registry.

Packaging:

npm pack

Generates dsh-agent-preset-branch-<version>.tgz; the files in package.json already lists the 6 files needed for running, with no build steps and no npm dependencies.

Typical Usage

  1. Session has multiple turns, switch mode entirely to continue
    Click the header mode capsule → Select target preset → Click “New Session with ‘[Mode Name]’” at the bottom. The new session inherits up to the end of the last completed turn, and jumps to the new session to continue.

  2. Cut from a specific turn in the middle to switch mode
    Click the target mode in the “Branch Mode” capsule below that turn’s completed reply, a single submission. The list will mark “Cut-off: End of Turn N”; the Turn 2 capsule will only migrate to the end of Turn 2, content after that will not follow.

  3. Switch preset before starting a new task
    When no turn has been run yet, the bottom of the header shows “Switch to ‘[Mode Name]’”, switching in place without creating a new session.

  4. Self-check mode consistency
    Request GET /dsh-agent-preset-branch/inspect?sessionId=… for a suspicious session, and view the agrees field and the preset fields on both sides.

Applicable Scenarios and Notes

Suitable for: Needs to retain conversation context within the same Workspace but continue with a different Agent preset (different tools and prompt sections); needs to precisely cut from historical turns for A/B style mode comparison.

Must be aware:

  • The cut-off point only recognizes turn/end of completed turns; half-turns or invalid atSeq will fall back to the default cut-off point, it won’t fail the whole order nor cut in the middle of a turn.
  • When cutting at a historical turn, independent accounting-type events between that turn and the next one will not be migrated.
  • The header agent-preset slot competes by priority; it will only show one among same-slot plugins like dsh-agent-preset-select. When installing this plugin, you should remove the predecessor from the profile dependencies and dsh.profile.bundles.
  • The community catalog SkillHub Plugin Page and GitHub repository are published by the maintainer, with no official affiliation with DeepSeek / High-Flyer; the DSH ecosystem philosophy is “Everything is a plugin”, and the catalog site is an independent community index.

Conclusion

dsh-agent-preset-branch binds “switching Agent preset” and “retaining conversation up to a certain turn” into a single “create new + seed migration”, bypassing DSH’s restrictions on forking and post-hoc mode changes. The two UI entry points share the same engine and routes, suitable for mode switching and historical cut-off branching in workflows.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye