@deepseek-ai/dsh-subagent-in-process-driver 0.1.1-rc.2 → 0.1.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # pnpm run verify-translation-pairing --write packages/subagent/subagent-in-process-driver/README.md
5
- README.md: 47a5c09fc1c80c5dc3062be82e7355b874a627d3
6
- README.zh.md: b96399795a0fbac05ef1795888aa93c620687f30
5
+ README.md: 4f343862d336a0cf697ab3bf5cf73f86d1d235fe
6
+ README.zh.md: a77032317c592f4431b9bba4f5e808f4da8eb702
package/README.md CHANGED
@@ -1,58 +1,104 @@
1
+ ---
2
+ description: "Shared in-process subagent run driver for maintainers and backend authors understanding or extending the spawn and fork run lifecycle."
3
+ kind: "package-library"
4
+ ---
5
+
1
6
  # @deepseek-ai/dsh-subagent-in-process-driver
2
7
 
3
8
  English | [中文](README.zh.md)
4
9
 
5
- This package is the shared run driver for the two in-process providers. Spawn passes no session seed; fork passes the parent's completed-turn prefix. Everything else—depth, child creation, optional child customization, result reading, cancellation, and disposal—has one implementation here.
10
+ ## Summary
11
+
12
+ `dsh-subagent-in-process-driver` is the shared run driver behind the two in-process subagent backends: it creates one child agent through the host's agent factory, applies per-child customization, drives one task to completion, and returns the child's own final output with a single quiescent disposal path. Spawn calls it with no session seed; fork calls it with the parent's completed-turn prefix. It is a library, not a standalone feature: provider backends call `startInProcessRun`, and nothing in a composition configures it. Read this page to understand the run lifecycle both in-process backends share.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Use this package](#use-this-package)
17
+ - [Understand the implementation](#understand-the-implementation)
18
+ - [Further Exploration](#further-exploration)
19
+ - [Model Experience](#model-experience)
20
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
21
+ - [Dev Note](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## Use this package
27
+
28
+ You reach this package through a provider backend, not a composition: `dsh-subagent-spawn-in-process` and `dsh-subagent-fork-in-process` each call `startInProcessRun(request, options)` and own everything around it. This page documents the lifecycle both share so you can read one backend's behavior and reason about the other.
29
+
30
+ ### What one run provides
31
+
32
+ One call starts and drives one one-shot child. Fulfillment means the child is already published in `ctx.agents` and the caller owns the returned run; a rejected start has already quiesced the unpublished creation, so no half-created child survives. The run exposes the child's id and live agent, a `result` promise, and a `dispose()` that stops the loop, removes the agent and session, and unwinds scoped registrations.
33
+
34
+ ### The one input
35
+
36
+ `InProcessRunOptions` is `{ seed?: SessionEvent[] }` — a fork seed of balanced parent events. Spawn omits it; fork supplies the completed-turn prefix and records its length so the result reader never mistakes seeded parent messages for child output.
37
+
38
+ ### What the child gets
6
39
 
7
- ## Start contract
40
+ The child receives the parent's working-directory/session lineage and inherits the parent provider, model, reasoning effort, and output-token cap unless `request.agentOptions` overrides them. It gets a fresh flat registration scope: parent tool restrictions and authority are not imported. A run carries the parent's explicit sandbox override and `'never'` approval pin into the child and appends a per-run descriptor inside the child's initial turn.
8
41
 
9
- `startInProcessRun(request, options): Promise<SubagentRun>` fulfills only after the child is published in `ctx.agents`. A rejected start has already quiesced the agent factory's unpublished creation transaction, so the caller never receives a half-created handle.
42
+ -----
43
+
44
+ <a id="understand-the-implementation"></a>
45
+ ## Understand the implementation
46
+
47
+ <details>
48
+ <summary>Implementation internals — click to expand</summary>
49
+
50
+ This section explains the driver's lifecycle contract and the structured-output runtime; the observable behavior is covered in [Use this package](#use-this-package).
51
+
52
+ ### Start contract
10
53
 
11
54
  The driver follows this sequence:
12
55
 
13
56
  1. Validate the parent depth and optional absolute `maxDepth`, then derive child depth as parent depth plus one and persist it in the child session header.
14
- 2. Call `parent.ctx.agents.create` directly, passing the required request signal into the factory's creation transaction.
57
+ 2. Create the child through the host agent factory with the caller's required signal threaded into the creation transaction.
15
58
  3. During that transaction's unpublished setup window, install the requested persona, tool restriction, and structured-output runtime.
16
- 4. Publish the child, retain the returned `AgentHandle`, and drive one task with `child.followup(prompt)` followed by `child.whenIdle()`.
17
- 5. Read the child's own output — its last non-empty assistant message (an empty-content message that records usage is skipped), or its accumulated assistant text when no such message exists — and the final durable turn reason from the complete owned child run, excluding any fork seed.
18
-
19
- The child gets the parent's working-directory/session lineage and inherits the parent provider, model, and output-token cap unless `request.agentOptions` overrides them. It gets a fresh flat registration scope: parent ownership does not import parent tool restrictions or establish an authority subset.
59
+ 4. Publish the child, retain the returned handle, and drive one task.
60
+ 5. Read the child's own output — its last non-empty assistant message, or its accumulated assistant text when none exists — and the final durable turn reason from the complete owned run, excluding any fork seed.
20
61
 
21
- This result boundary is valid because the provider owns an isolated child lifecycle from publication through quiescence. Steering submitted during that lifecycle belongs to the child run; the provider does not pretend the initial follow-up alone owns its output.
62
+ ### Cancellation and ownership
22
63
 
23
- The driver applies the seam's [delegated policy](../subagent/README.md#delegated-policy) through the shared child-agent helpers: it captures the parent's explicit sandbox override and the `'never'` approval pin before child creation and appends the source-tagged events during unpublished setup, after any fork history and before session publication. See the [delegation-policy decision](../../../.agents/notes/implemented/feature/2026-07-25-subagent-policy-inheritance.md).
64
+ The required request signal covers both startup and the live run. Before publication, the creation transaction observes it, rolls back, and rejects; the driver re-checks once after publication to close the handoff race, then installs a minimal live-run listener. After fulfillment the caller owns the run: provider unload does not revoke it, and `dispose()` removes the abort listener, records cancellation, and delegates to the handle's memoized quiescence transaction, which stops the loop, removes the agent and session, and unwinds scoped registrations. Cancellation owns every non-completed in-flight outcome and reports `aborted`; an already-completed turn remains completed.
24
65
 
25
- ## Cancellation and ownership
66
+ ### Structured output
26
67
 
27
- The required request signal covers both startup and the live run. Before publication, `AgentCreationTransaction` observes it, rolls back, and rejects. The factory detaches that creation-only listener before returning; the driver immediately checks the signal once more before installing a minimal live-run listener, closing the handoff race. After publication, abort cancels the child.
68
+ `attachStructuredRuntime(childCtx, schema)` installs the whole contract in the child's scope: a `structured_output` tool validates and stages the model's value against the requested schema; a trailing first-party order-9900 system-prompt section tells the child the tool call is the terminal answer; a `tools/result` observer commits a staged value only after the authoritative final tool result succeeds, including the enclosing `run_code` result for PTC mode sub-dispatch; and a monotonic tool guard blocks later calls after capture. A clean turn that never commits the required value reports `error`; the driver does not re-prompt. All registrations ride the child fiber and disappear with it.
28
69
 
29
- After fulfillment, the caller owns the run. Provider-plugin unload does not revoke it. `dispose()` removes the live abort listener, records cancellation, and delegates to the returned `AgentHandle.dispose()`, whose memoized quiescence transaction stops the loop, removes the agent and session, and unwinds scoped registrations. Cancellation owns every non-completed in-flight outcome and reports `aborted`; an already-completed turn remains completed.
70
+ ### Source map
30
71
 
31
- ## Spawn and fork inputs
72
+ | File | Role |
73
+ |---|---|
74
+ | [`src/index.ts`](src/index.ts) | Run driver: creation, one-turn drive, result reading, disposal |
75
+ | [`src/structured.ts`](src/structured.ts) | Structured-output runtime: capture tool, prompt section, guard, commit |
76
+ | [`src/invariant.ts`](src/invariant.ts) | Invariant companion |
32
77
 
33
- `InProcessRunOptions` is `{ seed?: SessionEvent[] }`. Spawn omits it. Fork supplies a balanced completed-turn prefix and records its length so the result reader never mistakes a seeded parent message for child output.
78
+ </details>
34
79
 
35
- Depth enforcement is internal to `startInProcessRun`: it reads the parent depth via `delegationDepthOf` (the persisted `SessionHeader.delegationDepth` is authoritative; runtime `AgentOptions.subagentDepth` may deepen but never lower it, so a resumed child keeps its budget), treats absence as top-level depth zero, rejects malformed stored values, and reports an attempted child depth above `maxDepth`. An unrepresentable depth above the safe-integer domain is a `RangeError`. The child depth is written to the child header, so it survives persistence and resume.
80
+ -----
36
81
 
37
- ## Structured output
82
+ <a id="further-exploration"></a>
83
+ ## Further Exploration
38
84
 
39
- `attachStructuredRuntime(childCtx, schema)` installs the whole contract in the child's scope:
85
+ Read these pages when the package-level contract is not enough; they move from the shared subagent model to the backends built on this driver and the delegation-policy decision.
40
86
 
41
- - A `structured_output` tool registered with the requested schema validates and stages the model's value.
42
- - An order-190 system-prompt section tells the child that the tool call is the terminal answer.
43
- - Both contributions are ordinary child-scoped registrations. An expert `system-prompt/assemble` listener may replace them and therefore owns preserving the structured-output protocol for that child.
44
- - A `tools/result` observer commits a staged value only after that execution's authoritative final tool result succeeds, including the enclosing `run_code` result for Code Mode sub-dispatch.
45
- - A monotonic tool guard blocks later calls after capture, and the structured-output execution's `concludeTurn()` marker ends the turn after the result commits.
87
+ - [Subagent subsystem](../../../docs/subsystems/subagent.md) start requests, results, provider contract, and in-process depth and seed.
88
+ - [dsh-subagent-spawn-in-process](../subagent-spawn-in-process/README.md) the fresh-child backend built on this driver.
89
+ - [dsh-subagent-fork-in-process](../subagent-fork-in-process/README.md) the seeded-child backend built on this driver.
90
+ - [Delegation-policy decision](../../../.agents/notes/implemented/feature/2026-07-25-subagent-policy-inheritance.md) how parent sandbox and approval policy reach the child.
46
91
 
47
- A clean turn that never commits the required structured value reports `error`; the driver does not re-prompt. All registrations ride the child fiber and disappear with it.
92
+ -----
48
93
 
94
+ <a id="model-experience"></a>
49
95
  ## Model Experience
50
96
 
51
97
  ### Child-agent request
52
98
 
53
99
  #### What the model sees
54
100
 
55
- The shared driver sends the task verbatim as the child's user message and, when requested, shadows the persona and restricts global tool schemas, lookup, execution, and Code Mode SDK bindings in the unpublished child's fresh scope; parent restrictions are not inherited, and standalone tool-guidance sections remain. Spawn supplies no history; fork supplies its balanced seed.
101
+ The shared driver sends the task verbatim as the child's user message and, when requested, shadows the persona and restricts global tool schemas, lookup, execution, and PTC mode SDK bindings in the unpublished child's fresh scope; parent restrictions are not inherited, and standalone tool-guidance sections remain. Spawn supplies no history; fork supplies its balanced seed.
56
102
 
57
103
  #### Token effect
58
104
 
@@ -66,7 +112,7 @@ Independent of the parent request cache. The child's later history is append-onl
66
112
 
67
113
  #### What the model sees
68
114
 
69
- A structured run adds the structured-output instruction below. It also adds a child-scoped `structured_output` definition with exact description `Report your final structured result. Call this exactly once, when your answer is complete; the arguments must match this tool's parameter schema exactly.` and the requested schema. This runtime-only definition is outside the generated shipped [tool package map](../../../docs/tool-catalog.md#tool-package-map). Its canonical acknowledgement is `{ recorded: true }`, rendered as `Structured output recorded.`; a later call becomes ``Error: structured output already recorded: the run is complete, so `<tool>` is not executed``.
115
+ A structured run adds the structured-output instruction below. It also adds a child-scoped `structured_output` definition with the requested schema and the exact description `Report your final structured result. Call this exactly once, when your answer is complete; the arguments must match this tool's parameter schema exactly.` This runtime-only definition is outside the generated shipped [tool package map](../../../docs/tool-catalog.md#tool-package-map). Its canonical acknowledgement is `{ recorded: true }`, rendered as `Structured output recorded.`; a later call becomes ``Error: structured output already recorded: the run is complete, so `<tool>` is not executed``.
70
116
 
71
117
  ##### Structured-output instruction
72
118
 
@@ -112,5 +158,20 @@ Append-only; newly visible content follows the reusable request prefix and does
112
158
 
113
159
  ## Known Limitations and Deferred Work
114
160
 
115
- - **Runs expose no `sendMessage`/`resume`** — the optional runtime capabilities are absent on in-process runs.
161
+ <a id="known-limitations-and-deferred-work"></a>
162
+
163
+
164
+ These limits define what an in-process one-shot run cannot do; they are current package constraints.
165
+
166
+ - **Runs expose no `sendMessage`/`resume`** — the optional runtime capabilities are absent on in-process one-shot runs.
116
167
  - **Structured capture accepts the `defineTool` schema subset only** — unsupported JSON Schema constructs fail before the child is created; a provider needing a broader schema vocabulary requires a different runtime.
168
+
169
+ <a id="dev-note"></a>
170
+ ### Dev Note
171
+
172
+ <details>
173
+ <summary>Working context for maintainers — click to expand</summary>
174
+
175
+ None.
176
+
177
+ </details>
package/README.zh.md CHANGED
@@ -1,72 +1,118 @@
1
+ ---
2
+ description: "共享进程内 subagent 运行驱动器,供维护者与后端作者理解或扩展 spawn 与 fork 的运行生命周期。"
3
+ kind: "package-library"
4
+ ---
5
+
1
6
  # @deepseek-ai/dsh-subagent-in-process-driver
2
7
 
3
8
  [English](README.md) | 中文
4
9
 
5
- 本包是两个进程内提供方共用的运行驱动器。spawn 不传入会话初始内容;fork 传入父 agent(智能体)已完成轮次的前缀。其余机制,包括深度、子 agent 创建、可选的子 agent 定制、结果读取、取消和 dispose(资源释放),都在此共用同一套实现。
10
+ ## 概述
6
11
 
7
- ## 启动约定
12
+ `dsh-subagent-in-process-driver` 是两个进程内 subagent 后端共用的运行驱动器:它通过宿主的 agent 工厂创建一个子 agent,应用按子 agent 的定制,把一项任务驱动到完成,并以单一完全停稳的 dispose(资源释放)路径返回子 agent 自身的最终输出。spawn 调用它时不传入会话初始内容;fork 调用它时传入父级已完成轮次的前缀。它是库而非独立功能:提供方后端调用 `startInProcessRun`,组合中没有任何东西配置它。阅读本页可理解两个进程内后端共享的运行生命周期。
8
13
 
9
- `startInProcessRun(request, options): Promise<SubagentRun>` 只在子 agent 发布到 `ctx.agents` 后才兑现。启动被拒绝时,agent 工厂的未发布创建事务已经完全停稳,因此调用方绝不会收到创建到一半的句柄。
14
+ ## 目录
10
15
 
11
- 驱动器按以下顺序运行:
16
+ - [使用本包](#use-this-package)
17
+ - [理解实现](#understand-the-implementation)
18
+ - [进一步探索](#further-exploration)
19
+ - [模型体验](#model-experience)
20
+ - [已知限制与延期工作](#known-limitations-and-deferred-work)
21
+ - [开发备注](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## 使用本包
27
+
28
+ 你通过提供方后端而非组合到达本包:`dsh-subagent-spawn-in-process` 与 `dsh-subagent-fork-in-process` 各自调用 `startInProcessRun(request, options)` 并拥有其外围的一切。本页记录两者共享的生命周期,使你读懂一个后端的行为后即可推断另一个。
29
+
30
+ ### 一次运行提供什么
31
+
32
+ 一次调用启动并驱动一个一次性子 agent。调用兑现意味着子 agent 已发布到 `ctx.agents`,调用方拥有返回的运行;启动被拒绝时,未发布的创建已经完全停稳,因此不会有创建到一半的子 agent 存活。运行暴露子 agent 的 id 与在线 agent、一个 `result` promise,以及一个 `dispose()`——它会停止循环、移除 agent 与会话,并撤销作用域内的注册。
33
+
34
+ ### 唯一输入
35
+
36
+ `InProcessRunOptions` 的形态为 `{ seed?: SessionEvent[] }`——fork 的已配平父级事件初始内容。spawn 省略该值;fork 提供已完成轮次前缀并记录其长度,使结果读取器不会把作为初始内容的父级消息误认为子 agent 输出。
37
+
38
+ ### 子 agent 获得什么
39
+
40
+ 子 agent 获得父级的工作目录/会话谱系,除非 `request.agentOptions` 覆盖,否则继承父级的提供方、模型、推理等级与输出 token 上限。它获得全新的扁平注册作用域:父级工具限制与权限不会被导入。一次运行会把父级显式的沙箱覆盖项与 `'never'` 审批钉定带入子 agent,并在子 agent 的初始轮次内追加一份按运行的描述符。
41
+
42
+ -----
12
43
 
13
- 1. 校验父 agent 深度和可选的绝对 `maxDepth`,然后把子 agent 深度推导为父 agent 深度加一,并将其持久化到子 agent 会话 header。
14
- 2. 直接调用 `parent.ctx.agents.create`,把必需的请求信号传入工厂的创建事务。
15
- 3. 在该事务未发布的设置窗口中,安装请求的 persona、工具限制和结构化输出运行时。
16
- 4. 发布子 agent,保留返回的 `AgentHandle`,并通过先调用 `child.followup(prompt)`、再调用 `child.whenIdle()` 来驱动一项任务。
17
- 5. 从完整的自有子运行中读取子 agent 自身的输出——最后一条非空 assistant 消息(记录 usage 的空内容消息会被跳过),若没有这类消息则取其累积的 assistant 文本——以及最终持久化的轮次原因,并排除任何 fork 初始内容。
44
+ <a id="understand-the-implementation"></a>
45
+ ## 理解实现
18
46
 
19
- 子 agent 会获得父 agent 的工作目录/会话谱系;除非 `request.agentOptions` 覆盖,否则还会继承父 agent 的提供方、模型和输出 token 上限。它获得全新的扁平注册作用域:父级所有权不会导入父 agent 的工具限制,也不会建立权限子集。
47
+ <details>
48
+ <summary>实现细节——点击展开</summary>
20
49
 
21
- 该结果边界成立,是因为提供方拥有从发布到完全停稳的隔离子 agent 生命周期。在该生命周期内提交的 steering(中途引导)属于子运行;提供方不会声称输出只归初始 follow-up 所有。
50
+ 本节解释驱动器的生命周期约定与结构化输出运行时;可观察行为已在[使用本包](#use-this-package)中说明。
22
51
 
23
- 驱动器通过共享的子 agent 辅助函数应用该 seam 的[委派策略](../subagent/README.zh.md#delegated-policy):它会在创建子 agent 前捕获父级的显式沙箱覆盖项与 `'never'` 审批钉定,并在未发布的设置阶段追加带来源标记的事件,使其位于所有 fork 历史之后、会话发布之前。参见[委派策略决策](../../../.agents/notes/implemented/feature/2026-07-25-subagent-policy-inheritance.zh.md)。
52
+ ### 启动约定
24
53
 
25
- ## 取消与所有权
54
+ 驱动器按以下顺序运行:
55
+
56
+ 1. 校验父级深度与可选的绝对 `maxDepth`,然后把子级深度推导为父级深度加一,并持久化到子级会话 header。
57
+ 2. 通过宿主 agent 工厂创建子 agent,并把调用方必需的信号传入创建事务。
58
+ 3. 在该事务未发布的设置窗口内,安装请求的 persona、工具限制与结构化输出运行时。
59
+ 4. 发布子 agent,保留返回的句柄,并驱动一项任务。
60
+ 5. 从完整的自有运行中读取子 agent 自身的输出——最后一条非空 assistant 消息,若无则取其累积的 assistant 文本——以及最终持久化的轮次原因,并排除任何 fork 初始内容。
61
+
62
+ ### 取消与所有权
26
63
 
27
- 必需的请求信号同时覆盖启动阶段和实时运行。发布前,`AgentCreationTransaction` 会观察该信号、回滚并拒绝。工厂返回前会移除仅用于创建阶段的监听器;驱动器随即再次检查信号,然后安装最小化的实时运行监听器,从而消除交接竞态。发布后,中止会取消子 agent
64
+ 必需的请求信号同时覆盖启动阶段与实时运行。发布前,创建事务会观察它、回滚并拒绝;驱动器在发布后再检查一次以消除交接竞态,然后安装最小化的实时运行监听器。兑现后,调用方拥有该运行:提供方插件卸载不会撤销它;`dispose()` 会移除中止监听器、记录取消,并委托给句柄经记忆化的完全停稳事务——后者停止循环、移除 agent 与会话,并撤销作用域内的注册。取消流程会接管所有尚未完成的进行中结果,并将其报告为 `aborted`;已经完成的轮次仍保持完成状态。
28
65
 
29
- 兑现后,调用方拥有该运行。提供方插件卸载不会撤销它。`dispose()` 会移除实时中止监听器、记录取消,并委托给返回的 `AgentHandle.dispose()`;后者通过经记忆化的完全停稳事务停止循环、移除 agent 和会话,并撤销作用域内的注册。取消流程会接管所有尚未完成的进行中结果,并将其报告为 `aborted`;已经完成的轮次仍保持完成状态。
66
+ ### 结构化输出
30
67
 
31
- ## spawn fork 输入
68
+ `attachStructuredRuntime(childCtx, schema)` 会在子 agent 作用域中安装完整约定:`structured_output` 工具按请求的 schema 校验并暂存模型值;位于末尾、first-party 顺序为 9900 的系统提示词段告诉子 agent 该工具调用就是终态答案;`tools/result` 观察器只在该次执行的权威最终工具结果成功后提交暂存值,包括 PTC mode 子分派外层的 `run_code` 结果;单调工具防护会在捕获后阻止后续调用。正常结束却始终未提交必需值的轮次会报告 `error`;驱动器不会重新提示。所有注册都附着于子 agent fiber,并随其一同消失。
32
69
 
33
- `InProcessRunOptions` 的形态为 `{ seed?: SessionEvent[] }`。spawn 省略该值。fork 提供已配平的已完成轮次前缀,并记录其长度,确保结果读取器不会把作为初始内容的父 agent 消息误认为子 agent 输出。
70
+ ### 源码地图
34
71
 
35
- 深度强制在 `startInProcessRun` 内部完成:它通过 `delegationDepthOf` 读取父 agent 深度(持久化的 `SessionHeader.delegationDepth` 具有权威性;运行时 `AgentOptions.subagentDepth` 可以加深但绝不能降低该值,因此恢复后的子 agent 会保留预算),缺失值按顶层深度零处理,拒绝格式错误的存储值,并报告尝试的子 agent 深度超过 `maxDepth`。超过安全整数范围、无法表示的深度会触发 `RangeError`。子 agent 深度写入子 agent header,因此会在持久化和恢复后保留。
72
+ | 文件 | 职责 |
73
+ |---|---|
74
+ | [`src/index.ts`](src/index.ts) | 运行驱动器:创建、单轮驱动、结果读取、dispose |
75
+ | [`src/structured.ts`](src/structured.ts) | 结构化输出运行时:捕获工具、提示词段、防护、提交 |
76
+ | [`src/invariant.ts`](src/invariant.ts) | 不变式伴生插件 |
36
77
 
37
- ## 结构化输出
78
+ </details>
38
79
 
39
- `attachStructuredRuntime(childCtx, schema)` 会在子 agent 作用域中安装完整约定:
80
+ -----
40
81
 
41
- - 使用请求 schema 注册的 `structured_output` 工具会校验并暂存模型值。
42
- - 一个顺序为 190 的系统提示词段会告诉子 agent,该工具调用就是终态答案。
43
- - 两项贡献都是普通的子 agent 作用域注册。专家级 `system-prompt/assemble` 监听器可以替换它们,因此负责为该子 agent 保留结构化输出协议。
44
- - `tools/result` 观察器只会在该次执行的权威最终工具结果成功后提交暂存值;Code Mode 子分派外层的 `run_code` 结果也包括在内。
45
- - 单调工具防护会在捕获值后阻止后续调用,结构化输出执行的 `concludeTurn()` 标记则在结果提交后结束轮次。
82
+ <a id="further-exploration"></a>
83
+ ## 进一步探索
46
84
 
47
- 正常结束却始终未提交必需结构化值的轮次会报告 `error`;驱动器不会重新提示。所有注册都附着于子 agent fiber,并随其一同消失。
85
+ 当包级约定不够用时阅读以下页面;它们从共享 subagent 模型进入构建于本驱动器之上的后端,以及委派策略决策。
48
86
 
87
+ - [Subagent 子系统](../../../docs/subsystems/subagent.zh.md)——启动请求、结果、提供方约定与进程内深度和初始内容。
88
+ - [dsh-subagent-spawn-in-process](../subagent-spawn-in-process/README.zh.md)——构建于本驱动器之上的全新子级后端。
89
+ - [dsh-subagent-fork-in-process](../subagent-fork-in-process/README.zh.md)——构建于本驱动器之上的初始内容子级后端。
90
+ - [委派策略决策](../../../.agents/notes/implemented/feature/2026-07-25-subagent-policy-inheritance.zh.md)——父级沙箱与审批策略如何到达子 agent。
91
+
92
+ -----
93
+
94
+ <a id="model-experience"></a>
49
95
  ## 模型体验
50
96
 
51
97
  ### 子 agent 请求
52
98
 
53
- #### 模型看到的内容
99
+ #### 模型看到什么
54
100
 
55
- 共享驱动器把任务逐字作为子 agent 的用户消息发送;若有请求,还会在未发布子 agent 的全新作用域中遮蔽 persona,并限制全局工具 schema、查找、执行和 Code Mode SDK 绑定。父 agent 的限制不会被继承,独立的工具指导段仍会保留。spawn 不提供历史;fork 提供平衡的初始内容。
101
+ 共享驱动器把任务逐字作为子 agent 的用户消息发送;若有请求,还会在未发布子 agent 的全新作用域中遮蔽 persona,并限制全局工具 schema、查找、执行与 PTC mode SDK 绑定。父级限制不会被继承,独立的工具指导段仍会保留。spawn 不提供历史;fork 提供其已配平的初始内容。
56
102
 
57
103
  #### Token 影响
58
104
 
59
- 子 agent 输入与父 agent 隔离,并通过子 agent 自身的步骤增长。persona 会改变重复提示词文本;过滤会改变 schema 或生成 SDK 的成本,但不影响独立注册的指导内容。
105
+ 子 agent 输入与父级隔离,并随子 agent 自身的步骤增长。persona 会改变重复提示词文本;过滤会改变 schema 或生成 SDK 的成本,但不影响独立注册的指导内容。
60
106
 
61
107
  #### KV Cache 影响
62
108
 
63
- 与父 agent 请求缓存相互独立。子 agent 后续历史仅追加,而 persona、工具过滤、生成 SDK、提供方或模型变化会建立不同的子 agent 前缀。
109
+ 与父级请求缓存相互独立。子 agent 后续历史仅追加,而 persona、工具过滤、生成 SDK、提供方或模型变化会建立不同的子 agent 前缀。
64
110
 
65
111
  ### 结构化输出系统提示词、schema 与结果
66
112
 
67
- #### 模型看到的内容
113
+ #### 模型看到什么
68
114
 
69
- 结构化运行会添加下方的结构化输出指令。它还会添加子 agent 作用域的 `structured_output` 定义,其精确描述为 `Report your final structured result. Call this exactly once, when your answer is complete; the arguments must match this tool's parameter schema exactly.`,参数使用请求的 schema。该仅运行时存在的定义不在已生成并随产品发布的[工具包索引](../../../docs/tool-catalog.zh.md#tool-package-map)中。其规范确认值是 `{ recorded: true }`,渲染为 `Structured output recorded.`;后续调用会变为 ``Error: structured output already recorded: the run is complete, so `<tool>` is not executed``。
115
+ 结构化运行会添加下方的结构化输出指令,并添加子 agent 作用域的 `structured_output` 定义,其参数使用请求的 schema,精确描述为 `Report your final structured result. Call this exactly once, when your answer is complete; the arguments must match this tool's parameter schema exactly.` 该仅运行时存在的定义不在已生成并随产品发布的[工具包索引](../../../docs/tool-catalog.zh.md#tool-package-map)中。其规范确认值是 `{ recorded: true }`,渲染为 `Structured output recorded.`;后续调用会变为 ``Error: structured output already recorded: the run is complete, so `<tool>` is not executed``。
70
116
 
71
117
  ##### 结构化输出指令
72
118
 
@@ -76,41 +122,56 @@ When you have your final answer, you MUST report it by calling the `structured_o
76
122
 
77
123
  #### Token 影响
78
124
 
79
- 固定指令和能力产生的 token 开销仅由该子 agent 承担。结果文本进入子 agent 历史,而只有捕获的值会成为父 agent 结果。
125
+ 固定指令与能力产生的 token 仅由该子 agent 承担。结果文本进入子 agent 历史,而只有捕获的值会成为父级结果。
80
126
 
81
127
  #### KV Cache 影响
82
128
 
83
- 只要结构化输出指令和 schema 不变,子 agent 内部的前缀就保持稳定。更改 schema 或能力可能从该早期片段开始使子 agent 缓存失效;结果会分别追加到子 agent 和父 agent 历史中。
129
+ 只要结构化输出指令与 schema 不变,子 agent 内部的前缀就保持稳定。更改 schema 或能力可能从该早期片段开始使子 agent 缓存失效;结果会分别追加到子 agent 与父级历史中。
84
130
 
85
- ### 父 agent 启动错误(间接)
131
+ ### 父级启动错误(间接)
86
132
 
87
- #### 模型看到的内容
133
+ #### 模型看到什么
88
134
 
89
135
  通过 `dsh-tool-subagent`,无效深度状态会精确变为 `Error: agent subagentDepth must be a non-negative safe integer`、`Error: subagent child depth exceeds the safe-integer range` 或 `Error: subagent depth <attempted> exceeds maxDepth <max>`。发布前取消的中止原因会通过注册表的 `Error: <message>` 包装传递。
90
136
 
91
137
  #### Token 影响
92
138
 
93
- 启动成功时为零 token;只有失败的父 agent 工具调用会保留这段文本。
139
+ 启动成功时为零 token;只有失败的父级工具调用会保留这段文本。
94
140
 
95
141
  #### KV Cache 影响
96
142
 
97
143
  仅追加;新增可见内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
98
144
 
99
- ### 父 agent 结果(间接)
145
+ ### 父级结果(间接)
100
146
 
101
- #### 模型看到的内容
147
+ #### 模型看到什么
102
148
 
103
- 驱动器只提取子 agent 自身最后的 assistant 输出或捕获的结构化值;作为初始内容的父 agent 消息和子 agent 中间工作不会成为结果。
149
+ 驱动器只提取子 agent 自身最后的 assistant 输出或捕获的结构化值;作为初始内容的父级消息与子 agent 中间工作不会成为结果。
104
150
 
105
151
  #### Token 影响
106
152
 
107
- agent 通过消费方接收一个依赖数据的结果;其他所有子 agent token 都留在子 agent 会话中。
153
+ 父级通过消费方接收一个依赖数据的结果;其他所有子 agent token 都留在子 agent 会话中。
108
154
 
109
155
  #### KV Cache 影响
110
156
 
111
157
  仅追加;新增可见内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
112
158
 
113
- ## 已知限制与暂缓事项
159
+ ## 已知限制与延期工作
160
+
161
+ <a id="known-limitations-and-deferred-work"></a>
162
+
163
+
164
+ 这些限制说明进程内一次性运行不能做什么;它们是当前包约束。
165
+
166
+ - **运行不公开 `sendMessage`/`resume`**——进程内一次性运行不具备这些可选运行时能力。
167
+ - **结构化捕获只接受 `defineTool` schema 子集**——不支持的 JSON Schema 构造会在子 agent 创建前失败;需要更广 schema 词汇的提供方必须采用不同的运行时。
168
+
169
+ <a id="dev-note"></a>
170
+ ### 开发备注
171
+
172
+ <details>
173
+ <summary>维护者的工作上下文——点击展开</summary>
174
+
175
+ 无。
114
176
 
115
- - **运行不公开 `sendMessage`/`resume`**:进程内运行不具备这些可选运行时能力。
116
- - **结构化捕获只接受 `defineTool` schema 子集**:不支持的 JSON Schema 构造会在子 agent 创建前失败;需要更广 schema 词汇的提供方必须采用不同的运行时。
177
+ </details>
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { brandString } from "@deepseek-ai/dsh-brand";
2
3
  import { foldConsumedWork } from "@deepseek-ai/dsh-agent";
3
- import { SessionId } from "@deepseek-ai/dsh-session";
4
4
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
5
5
  import { appendDelegatedPolicyOverrides, applyChildComposition, assertSubagentMaxDepth, captureDelegatedPolicyOverrides, childSessionMeta, finalAssistantOutput, resolveChildAgentOptions, resolveChildDepth } from "@deepseek-ai/dsh-subagent";
6
6
  import { ToolArgsError, validateJsonSchemaValue } from "@deepseek-ai/dsh-tools";
@@ -11,7 +11,7 @@ import { ToolArgsError, validateJsonSchemaValue } from "@deepseek-ai/dsh-tools";
11
11
  * scope, so concurrent runs do not interact and disposal leaves no global residue. The prompt
12
12
  * contribution is ordinary reconstructed request state.
13
13
  *
14
- * Capture commits only after the authoritative `tools/result` succeeds; Code Mode capture also
14
+ * Capture commits only after the authoritative `tools/result` succeeds; PTC mode capture also
15
15
  * waits for the enclosing `run_code` result. The terminal result marker and monotonic tool
16
16
  * guard prevent later calls from reopening a completed structured run.
17
17
  * @module @deepseek-ai/dsh-subagent-in-process-driver/structured
@@ -19,8 +19,8 @@ import { ToolArgsError, validateJsonSchemaValue } from "@deepseek-ai/dsh-tools";
19
19
  /** The model-facing tool name a structured child must call to finish. */
20
20
  const STRUCTURED_OUTPUT_TOOL = "structured_output";
21
21
  /**
22
- * The instruction registered as the child's trailing (order-190, the end of
23
- * the tool-guidance band) scoped prompt section: the demand travels with the
22
+ * The instruction registered as the child's trailing scoped prompt section:
23
+ * the demand travels with the
24
24
  * tool, as ordinary prompt state of exactly one agent.
25
25
  */
26
26
  const STRUCTURED_OUTPUT_INSTRUCTION = `When you have your final answer, you MUST report it by calling the \`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. Do not finish with a plain text answer: only the tool call counts as your result.`;
@@ -78,7 +78,7 @@ function attachStructuredRuntime(childCtx, schema) {
78
78
  });
79
79
  childCtx.systemPrompt.section({
80
80
  name: `tool:${STRUCTURED_OUTPUT_TOOL}`,
81
- order: 190,
81
+ order: childCtx.systemPrompt.getSectionOrder("STRUCTURED_OUTPUT"),
82
82
  text: STRUCTURED_OUTPUT_INSTRUCTION
83
83
  });
84
84
  childCtx.tools.guard((exec) => captured === void 0 && pending === void 0 ? void 0 : `structured output already recorded: the run is complete, so \`${exec.name}\` is not executed`);
@@ -101,7 +101,7 @@ function attachStructuredRuntime(childCtx, schema) {
101
101
  const entry = pending;
102
102
  pending = void 0;
103
103
  if (result.isError) return;
104
- /* v8 ignore else -- Code Mode serializes outer executions, so the guard blocks every later supported call */
104
+ /* v8 ignore else -- PTC mode serializes outer executions, so the guard blocks every later supported call */
105
105
  if (captured === void 0) captured = { value: entry.value };
106
106
  });
107
107
  return { captured: () => captured };
@@ -162,7 +162,7 @@ async function startInProcessRun(request, options) {
162
162
  if (request.signal.aborted) throw prePublicationAbort();
163
163
  const parent = request.parent;
164
164
  const childDepth = resolveChildDepth(parent, request.maxDepth);
165
- const childId = SessionId(randomUUID());
165
+ const childId = brandString(randomUUID());
166
166
  const seed = options.seed;
167
167
  const activationBoundary = seed?.length ?? 0;
168
168
  const inherited = captureDelegatedPolicyOverrides(parent);
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * @module @deepseek-ai/dsh-subagent-in-process-driver
12
12
  */
13
- import { type SessionEvent } from '@deepseek-ai/dsh-session';
13
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
14
14
  import type { ResolvedSubagentStartRequest, SubagentRun } from '@deepseek-ai/dsh-subagent';
15
15
  export { STRUCTURED_OUTPUT_TOOL, STRUCTURED_OUTPUT_INSTRUCTION, } from './structured.ts';
16
16
  /** Extra inputs the spawn and fork providers supply to the shared driver. */
@@ -4,7 +4,7 @@
4
4
  * scope, so concurrent runs do not interact and disposal leaves no global residue. The prompt
5
5
  * contribution is ordinary reconstructed request state.
6
6
  *
7
- * Capture commits only after the authoritative `tools/result` succeeds; Code Mode capture also
7
+ * Capture commits only after the authoritative `tools/result` succeeds; PTC mode capture also
8
8
  * waits for the enclosing `run_code` result. The terminal result marker and monotonic tool
9
9
  * guard prevent later calls from reopening a completed structured run.
10
10
  * @module @deepseek-ai/dsh-subagent-in-process-driver/structured
@@ -14,8 +14,8 @@ import { type ObjectJsonSchema } from '@deepseek-ai/dsh-tools';
14
14
  /** The model-facing tool name a structured child must call to finish. */
15
15
  export declare const STRUCTURED_OUTPUT_TOOL = "structured_output";
16
16
  /**
17
- * The instruction registered as the child's trailing (order-190, the end of
18
- * the tool-guidance band) scoped prompt section: the demand travels with the
17
+ * The instruction registered as the child's trailing scoped prompt section:
18
+ * the demand travels with the
19
19
  * tool, as ordinary prompt state of exactly one agent.
20
20
  */
21
21
  export declare const STRUCTURED_OUTPUT_INSTRUCTION: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-subagent-in-process-driver",
3
3
  "description": "Shared in-process subagent run driver: drives a child agent on ctx.agents (used by the spawn and fork backends)",
4
- "version": "0.1.1-rc.2",
4
+ "version": "0.1.2-alpha.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -32,32 +32,36 @@
32
32
  ],
33
33
  "license": "MIT",
34
34
  "peerDependencies": {
35
- "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
36
- "@deepseek-ai/dsh-agent": "^0.1.1-rc.2",
37
- "@deepseek-ai/dsh-subagent": "^0.1.1-rc.2",
38
- "@deepseek-ai/dsh-session": "^0.1.1-rc.2",
39
- "@deepseek-ai/dsh-llm": "^0.1.1-rc.2",
40
- "@deepseek-ai/dsh-system-prompt": "^0.1.1-rc.2",
41
- "@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
42
- "@deepseek-ai/cordis": "^4.0.1"
35
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
36
+ "@deepseek-ai/dsh-llm": "^0.1.2-alpha.2",
37
+ "@deepseek-ai/dsh-session": "^0.1.2-alpha.2",
38
+ "@deepseek-ai/dsh-agent": "^0.1.2-alpha.2",
39
+ "@deepseek-ai/dsh-system-prompt": "^0.1.2-alpha.2",
40
+ "@deepseek-ai/dsh-tools": "^0.1.2-alpha.2",
41
+ "@deepseek-ai/cordis": "^4.0.2",
42
+ "@deepseek-ai/dsh-subagent": "^0.1.2-alpha.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@deepseek-ai/cordis-plugin-include": "^1.0.6",
46
- "@deepseek-ai/cordis-plugin-loader": "^1.0.2",
47
- "@deepseek-ai/dsh-agent": "^0.1.1-rc.2",
48
- "@deepseek-ai/dsh-agent-loop": "^0.1.1-rc.2",
49
- "@deepseek-ai/dsh-agent-loop-testkit": "^0.1.1-rc.2",
50
- "@deepseek-ai/dsh-agent-presets": "^0.1.1-rc.2",
51
- "@deepseek-ai/dsh-llm": "^0.1.1-rc.2",
52
- "@deepseek-ai/dsh-sandbox-policy": "^0.1.1-rc.2",
53
- "@deepseek-ai/dsh-session": "^0.1.1-rc.2",
54
- "@deepseek-ai/dsh-subagent": "^0.1.1-rc.2",
55
- "@deepseek-ai/dsh-system-prompt": "^0.1.1-rc.2",
56
- "@deepseek-ai/dsh-tool-fs": "^0.1.1-rc.2",
57
- "@deepseek-ai/dsh-fs-sandbox": "^0.1.1-rc.2",
58
- "@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
59
- "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
60
- "@deepseek-ai/cordis": "^4.0.1",
61
- "@deepseek-ai/dsh-user-approval": "^0.1.1-rc.2"
45
+ "@deepseek-ai/cordis": "^4.0.2",
46
+ "@deepseek-ai/cordis-plugin-include": "^1.0.7",
47
+ "@deepseek-ai/cordis-plugin-loader": "^1.0.3",
48
+ "@deepseek-ai/dsh-agent": "^0.1.2-alpha.2",
49
+ "@deepseek-ai/dsh-agent-loop": "^0.1.2-alpha.2",
50
+ "@deepseek-ai/dsh-agent-loop-testkit": "^0.1.2-alpha.2",
51
+ "@deepseek-ai/dsh-agent-presets": "^0.1.2-alpha.2",
52
+ "@deepseek-ai/dsh-fs-sandbox": "^0.1.2-alpha.2",
53
+ "@deepseek-ai/dsh-llm": "^0.1.2-alpha.2",
54
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
55
+ "@deepseek-ai/dsh-sandbox-policy": "^0.1.2-alpha.2",
56
+ "@deepseek-ai/dsh-subagent": "^0.1.2-alpha.2",
57
+ "@deepseek-ai/dsh-system-prompt": "^0.1.2-alpha.2",
58
+ "@deepseek-ai/dsh-tool-fs": "^0.1.2-alpha.2",
59
+ "@deepseek-ai/dsh-session": "^0.1.2-alpha.2",
60
+ "@deepseek-ai/dsh-user-approval": "^0.1.2-alpha.2",
61
+ "@deepseek-ai/dsh-tools": "^0.1.2-alpha.2",
62
+ "@deepseek-ai/dsh-session-projection": "^0.1.2-alpha.2"
63
+ },
64
+ "dependencies": {
65
+ "@deepseek-ai/dsh-brand": "^0.1.2-alpha.2"
62
66
  }
63
67
  }