Files
deepseek-harness/packages/subagent/subagent-fork
Tianyi Cui f256f3961d feat(system-prompt): prompt variables, persona-as-section, tool-guidance ownership
One principle: every fact in the assembled prompt has exactly one owner.

- dsh-system-prompt: merge-extensible AssembleContext on assemble();
  a variable(name, provider) registry; {{name}} interpolation in
  renderPrompt, strict (unknown/valueless/malformed references throw);
  duplicate section and variable names rejected; assembly carries
  resolved section text + variables through the assemble waterfall.
- dsh-agent declares AssembleContext.agent; dsh-agent-loop registers
  the agent:persona section (order 0 - identity renders before tool
  guidance) and the model/cwd variables, and drops its string join:
  renderPrompt(assembly) IS the full prompt.
- Tool guidance moves to its owners: descriptions carry per-tool
  semantics; sections only cross-call habits (tool:bash exit-code
  habit at order 105; read's not-shell nudge). todo/subagent need no
  section - their descriptions already carry the contract.
- SubagentProvider.inheritsParentContext (spawn/acp false, fork true);
  dsh-tool-subagent derives truthful per-provider wording and resolves
  the provider at load (backend must be listed first).
- Example personas shrink to identity + behavior with {{model}} (and
  {{cwd}} in the ACP tree); the welcome banner stops enumerating tools.

RFC: docs/rfc/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.md
2026-07-05 01:54:46 +08:00
..

@deepseek-ai/dsh-subagent-fork

The in-process fork subagent backend: a SubagentProvider that runs each child as a child Agent seeded with a prefix of the parent's session log — so the child inherits the parent's conversation context instead of starting fresh. Shares the run driver (startInProcessRun) with dsh-subagent-spawn; the only difference is the seed.

The seed boundary (the crux)

At the moment a subagent tool's execute runs, the parent's CURRENT turn is open and unbalanced: the log holds the assistant/message carrying this spawn's tool-call and the dangling tool/call with no tool/result yet. Seeding that raw prefix would give the child an open turn that the session constructor and the dev-mode invariants replay reject.

So the fork seeds only the balanced completed-turn prefix — the parent's log up to and including its last turn/end, excluding the in-flight turn entirely (completedTurnPrefix). Because the live log keeps seq === index, the slice is contiguous-from-0 and a valid seed. A parent on its very first (not-yet-complete) turn forks an empty seed — i.e. effectively a fresh child.

The seam this rides on: CreateAgentOptions.seed (added on dsh-agent, threaded through AgentLoop.createAgentctx.sessions.prepare({ seed })), the same primitive resume uses.

Capabilities

{ outputSchema: false, depthLimit: true, toolFilter: false } — identical to spawn (the depth/model/output behavior is the shared driver's).

Config

Key Meaning
providerName Registry name on ctx.subagents (default fork).

See dsh-subagent-spawn for the run lifecycle, model inheritance, and depth tracking — all shared.