@deepseek-ai/dsh-tool-subagent 0.2.1-alpha.1 → 0.2.1-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 +51 -51
- package/README.md +27 -29
- package/README.zh.md +26 -28
- package/lib/index.js +108 -237
- package/lib/types/index.d.ts +2 -16
- package/package.json +22 -26
package/README.i18n.yaml
CHANGED
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
en: 686fb5136bef0a3b
|
|
10
10
|
zh: d25d6569174a01b5
|
|
11
11
|
/deepseek-ai-dsh-tool-subagent/summary:
|
|
12
|
-
en:
|
|
13
|
-
zh:
|
|
12
|
+
en: 958d2b1c56ac6ec7
|
|
13
|
+
zh: cc1997a9ac09e7a5
|
|
14
14
|
/deepseek-ai-dsh-tool-subagent/table-of-contents:
|
|
15
15
|
en: d152484eb41ac6b4
|
|
16
16
|
zh: 09388d293f9be9cb
|
|
17
17
|
/deepseek-ai-dsh-tool-subagent/use-this-package:
|
|
18
|
-
en:
|
|
19
|
-
zh:
|
|
18
|
+
en: 93f1701f5209ecb5
|
|
19
|
+
zh: 6310fd012400aead
|
|
20
20
|
/deepseek-ai-dsh-tool-subagent/use-this-package/minimal-configuration:
|
|
21
|
-
en:
|
|
22
|
-
zh:
|
|
23
|
-
/deepseek-ai-dsh-tool-subagent/use-this-package/
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
21
|
+
en: d01d4425bc1875dd
|
|
22
|
+
zh: f3d36c8a1e5ed0fa
|
|
23
|
+
/deepseek-ai-dsh-tool-subagent/use-this-package/managed-delegation:
|
|
24
|
+
en: 42673064ba88a211
|
|
25
|
+
zh: 8fa26285bd649dc9
|
|
26
26
|
/deepseek-ai-dsh-tool-subagent/use-this-package/selecting-a-child-llm:
|
|
27
27
|
en: 0d37e3b3957515e4
|
|
28
28
|
zh: ea1a94b2f29e7d9a
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/design-concept:
|
|
33
33
|
en: 5ceacfed4ea0c648
|
|
34
34
|
zh: 005284534923d854
|
|
35
|
-
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/
|
|
36
|
-
en:
|
|
37
|
-
zh:
|
|
38
|
-
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
35
|
+
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/activation-ownership:
|
|
36
|
+
en: ef692c4d17290920
|
|
37
|
+
zh: b1d0d3dab011e2cd
|
|
38
|
+
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/result-acknowledgement:
|
|
39
|
+
en: 3cdb913209febc42
|
|
40
|
+
zh: ea6ebfbe9d21fb3e
|
|
41
41
|
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/context-sensitive-wording:
|
|
42
42
|
en: 1733728ac5aa6bb0
|
|
43
43
|
zh: 341ffc6e21a289af
|
|
44
44
|
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/source-map:
|
|
45
|
-
en:
|
|
46
|
-
zh:
|
|
45
|
+
en: 255f6edd3064ff2f
|
|
46
|
+
zh: c3ebfe1e845dfb4b
|
|
47
47
|
/deepseek-ai-dsh-tool-subagent/further-exploration:
|
|
48
|
-
en:
|
|
49
|
-
zh:
|
|
48
|
+
en: fa3c9a967b636afb
|
|
49
|
+
zh: a9ce930a9766d5cb
|
|
50
50
|
/deepseek-ai-dsh-tool-subagent/model-experience:
|
|
51
51
|
en: 215e7ba838619b7b
|
|
52
52
|
zh: a311da3843709f90
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
en: e4c7376d4f29dbd5
|
|
55
55
|
zh: 6b7a9eaf69c9ea53
|
|
56
56
|
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema/what-the-model-sees:
|
|
57
|
-
en:
|
|
58
|
-
zh:
|
|
57
|
+
en: 12c872e4264bb6c0
|
|
58
|
+
zh: 20f870a78ebf8d29
|
|
59
59
|
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema/token-effect:
|
|
60
|
-
en:
|
|
61
|
-
zh:
|
|
60
|
+
en: 02da2a5e0a75fd91
|
|
61
|
+
zh: fd2d8b11386fc83d
|
|
62
62
|
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema/kv-cache-effect:
|
|
63
63
|
en: 46f736c6c389052a
|
|
64
64
|
zh: a7765541030e9104
|
|
@@ -78,44 +78,44 @@
|
|
|
78
78
|
en: cf78b9dd5596495f
|
|
79
79
|
zh: bd44560f8c2435e8
|
|
80
80
|
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/what-the-model-sees:
|
|
81
|
-
en:
|
|
82
|
-
zh:
|
|
81
|
+
en: 5f6611a932063e58
|
|
82
|
+
zh: effededa44c716af
|
|
83
83
|
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/what-the-model-sees/tool-guidance-section:
|
|
84
84
|
en: 82b3cd08b3961c98
|
|
85
85
|
zh: bdc2a34bcea16cac
|
|
86
86
|
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/token-effect:
|
|
87
|
-
en:
|
|
88
|
-
zh:
|
|
87
|
+
en: 58ee76659f75c73e
|
|
88
|
+
zh: 726c5b789e96677c
|
|
89
89
|
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/kv-cache-effect:
|
|
90
|
-
en:
|
|
91
|
-
zh:
|
|
92
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
93
|
-
en:
|
|
94
|
-
zh:
|
|
95
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
96
|
-
en:
|
|
97
|
-
zh:
|
|
98
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
99
|
-
en:
|
|
100
|
-
zh:
|
|
101
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
90
|
+
en: eaee0378bf87c980
|
|
91
|
+
zh: 2783a481ee349f1e
|
|
92
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/start-result:
|
|
93
|
+
en: 45854c8f4da73af7
|
|
94
|
+
zh: 7a9803ca8c03c40f
|
|
95
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/start-result/what-the-model-sees:
|
|
96
|
+
en: 15772cb4c28bf562
|
|
97
|
+
zh: 7452e7a7114d587c
|
|
98
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/start-result/token-effect:
|
|
99
|
+
en: 807d71626c81c858
|
|
100
|
+
zh: ba4b85709fa46c84
|
|
101
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/start-result/kv-cache-effect:
|
|
102
102
|
en: f5d5f97a153f7c70
|
|
103
103
|
zh: 3d6bc05b9eadfbc2
|
|
104
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
105
|
-
en:
|
|
106
|
-
zh:
|
|
107
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
108
|
-
en:
|
|
109
|
-
zh:
|
|
110
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
111
|
-
en:
|
|
112
|
-
zh:
|
|
113
|
-
/deepseek-ai-dsh-tool-subagent/model-experience/
|
|
104
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/completion-delivery:
|
|
105
|
+
en: b6ed0eef154aa546
|
|
106
|
+
zh: 34160884aa30ffec
|
|
107
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/completion-delivery/what-the-model-sees:
|
|
108
|
+
en: 8f5e3a083eb7f807
|
|
109
|
+
zh: 6bfc2b38f49a6f79
|
|
110
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/completion-delivery/token-effect:
|
|
111
|
+
en: 615348e27c0c9bc0
|
|
112
|
+
zh: 1655fdbc42932909
|
|
113
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/completion-delivery/kv-cache-effect:
|
|
114
114
|
en: f5d5f97a153f7c70
|
|
115
115
|
zh: 3d6bc05b9eadfbc2
|
|
116
116
|
/deepseek-ai-dsh-tool-subagent/known-limitations-and-deferred-work:
|
|
117
|
-
en:
|
|
118
|
-
zh:
|
|
117
|
+
en: 40e99fb684ccffc4
|
|
118
|
+
zh: 08c6820c7a5343e8
|
|
119
119
|
/deepseek-ai-dsh-tool-subagent/known-limitations-and-deferred-work/dev-note:
|
|
120
120
|
en: e67f633dc6fe7773
|
|
121
121
|
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
|
|
|
9
9
|
|
|
10
10
|
## Summary
|
|
11
11
|
|
|
12
|
-
Use this package to give an agent a named tool that delegates work to a configured
|
|
12
|
+
Use this package to give an agent a named tool that delegates work to a configured backend. Every call starts a managed activation and returns a child id; the runtime owns completion notices and cleanup. Local children support messages and restoration, while external backends execute one task and return their final answer through the completion notice. Supported backends can expose approved child LLM routes. Each instance can set child persona, tool access, and depth limits.
|
|
13
13
|
|
|
14
14
|
## Table of Contents
|
|
15
15
|
|
|
@@ -25,6 +25,8 @@ Use this package to give an agent a named tool that delegates work to a configur
|
|
|
25
25
|
<a id="use-this-package"></a>
|
|
26
26
|
## Use this package
|
|
27
27
|
|
|
28
|
+
The optional `cwd` argument selects the child's initial working directory. Relative paths resolve against the caller's current directory; omission inherits it. Existing children retain their own directories when the caller changes directory.
|
|
29
|
+
|
|
28
30
|
Mount one instance per delegation target, each with a distinct `toolName`. The tool exists exactly while its provider does, so sibling load order and provider reloads never strand it.
|
|
29
31
|
|
|
30
32
|
### Minimal configuration
|
|
@@ -45,8 +47,6 @@ Load the subagent service, an in-process or remote backend, and this tool; then
|
|
|
45
47
|
| `provider` | required | Provider name on `ctx.subagents` (e.g. `spawn`, `fork`, `acp`) |
|
|
46
48
|
| `toolName` | `subagent` | Model-facing tool name; distinct for every loaded instance |
|
|
47
49
|
| `modelSelectionSettings` | `false` | Sample the Host's exact-route authorization preference for each top-level Session; a standing preset observes matching Sessions, while direct Agent setup passes its Session explicitly; requires provider `agentOptions` support |
|
|
48
|
-
| `enableRunInBackground` | `true` | Expose `run_in_background`; disabling also rejects forced background calls |
|
|
49
|
-
| `backgroundMode` | `one-shot` | Background policy: `one-shot` defaults calls to foreground; `continuable` defaults them to background and requires the provider's `prepareContinuable` capability |
|
|
50
50
|
| `agentOptions` | — | Configured child `provider`, `model`, adapter-owned `reasoningEffort`, and positive `maxTokens` defaults; requires provider `agentOptions` support and overlays any provider-owned route defaults |
|
|
51
51
|
| `persona` | — | Per-child persona; requires the provider's `persona` capability |
|
|
52
52
|
| `toolFilter` | — | Per-child global-tool restriction; requires the `toolFilter` capability |
|
|
@@ -54,11 +54,11 @@ Load the subagent service, an in-process or remote backend, and this tool; then
|
|
|
54
54
|
|
|
55
55
|
The generated [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-tool-subagent) is the exhaustive source for every accepted field and its JSDoc.
|
|
56
56
|
|
|
57
|
-
###
|
|
57
|
+
### Managed delegation
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
Every call returns `started subagent <childId>` after the runtime accepts the child. It does not wait for the child's result. The activation owns the work independently of the completed tool call; the runtime sends a completion notice and releases execution resources.
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
Every backend’s completion notice carries its final answer. Local Spawn and Fork children can also send messages, accept more work through `send_message` while active, or resume after settling. Codex, Claude Code, ACP, and DSH SDK backends do not accept follow-up messages.
|
|
62
62
|
|
|
63
63
|
`maxDepth` caps recursion (`0` forbids delegation); omission reads the current Host `subagent.maxDepth` setting, initially `1`, at each delegation. A numeric depth requires a provider with the `depthLimit` capability; `'provider-managed'` leaves the budget to an out-of-process provider. `persona` and `toolFilter` configure every child when the provider supports them, and the tool stays visible at the cap — each attempted start checks the calling agent's current depth and rejects with an errored result.
|
|
64
64
|
|
|
@@ -82,13 +82,13 @@ This section explains how the tool mirrors provider lifecycle and settles runs;
|
|
|
82
82
|
|
|
83
83
|
One instance is one provider plus one tool name. The plugin mirrors provider lifecycle: it registers the tool when the named provider appears and disposes it when the provider leaves, so sibling load order and HMR replacement cannot strand a dangling tool. Direct Agent setup passes its unpublished Session explicitly and awaits installation before publication. A settings-backed standing preset receives each matching Agent through `agent/created`, selects policy from its Session, and awaits installation through its Context; installation failure rejects creation. A numeric `maxDepth` or configured LLM selection the provider cannot enforce fails the mount instead of the first delegation. At most one instance in a tool scope may own model selection because `list_subagent_models` has a global name.
|
|
84
84
|
|
|
85
|
-
###
|
|
85
|
+
### Activation ownership
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
The tool calls `ctx.subagents.startActivation()` with parent delivery selected. The runtime owns startup cancellation, execution, outcome reporting, and cleanup. A startup failure is an errored tool result; failures after publication arrive through the completion notice, with diagnostics and partial output preserved by the runtime.
|
|
88
88
|
|
|
89
|
-
###
|
|
89
|
+
### Result acknowledgement
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
The canonical tool result is `{ kind: 'activation', subagentId }`. It contains no execution Promise or final output; programmatic consumers that need to await results use the subagent service directly.
|
|
92
92
|
|
|
93
93
|
### Context-sensitive wording
|
|
94
94
|
|
|
@@ -98,7 +98,7 @@ The tool's description derives from `provider.inheritsParentContext`: a fresh ch
|
|
|
98
98
|
|
|
99
99
|
| File | Role |
|
|
100
100
|
|---|---|
|
|
101
|
-
| [`src/index.ts`](src/index.ts) | Tool registration, lifecycle mirroring,
|
|
101
|
+
| [`src/index.ts`](src/index.ts) | Tool registration, provider lifecycle mirroring, activation requests |
|
|
102
102
|
| [`src/model-selection.ts`](src/model-selection.ts) | Request/config merge and live LLM route preflight |
|
|
103
103
|
| [`src/model-selection-settings.ts`](src/model-selection-settings.ts) | Host-owned opt-in setting sampled for new Sessions |
|
|
104
104
|
| [`src/model-selection-state.ts`](src/model-selection-state.ts) | Session event that records and inherits the sampled decision |
|
|
@@ -113,12 +113,11 @@ The tool's description derives from `provider.inheritsParentContext`: a fresh ch
|
|
|
113
113
|
|
|
114
114
|
Read these pages when the package-level contract is not enough; they move from the tool's runtime behavior to the seam it delegates over and the adjacent child tools.
|
|
115
115
|
|
|
116
|
-
- [Subagent subsystem](../../../docs/subsystems/subagent.md) — providers,
|
|
116
|
+
- [Subagent subsystem](../../../docs/subsystems/subagent.md) — providers, activations, results, and continuation.
|
|
117
117
|
- [dsh-tool-subagent-control](../tool-subagent-control/README.md) — messaging, interrupt, and listing tools for continuable children.
|
|
118
|
-
- [Generated tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-tool-subagent) — the default schema and
|
|
118
|
+
- [Generated tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-tool-subagent) — the default schema and backend-specific wording.
|
|
119
119
|
- [Generated configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-tool-subagent) — every accepted config field.
|
|
120
|
-
- [
|
|
121
|
-
- [historical Model-selected subagent routes](../../../.agents/notes/archived/feature/2026-08-18-model-selected-subagent-routes.md) — selection policy, inheritance, discovery, and the fork restriction.
|
|
120
|
+
- [Historical model-selected subagent routes](../../../.agents/notes/archived/feature/2026-08-18-model-selected-subagent-routes.md) — selection policy, inheritance, discovery, and the fork restriction.
|
|
122
121
|
|
|
123
122
|
-----
|
|
124
123
|
|
|
@@ -129,11 +128,11 @@ Read these pages when the package-level contract is not enough; they move from t
|
|
|
129
128
|
|
|
130
129
|
#### What the model sees
|
|
131
130
|
|
|
132
|
-
The
|
|
131
|
+
The generated default [`subagent` schema](../../../docs/tool-catalog.md#deepseek-aidsh-tool-subagent) appears under the configured tool name while its provider exists. An enabled Session policy adds `provider`, `model`, and `reasoning_effort` plus route guidance; the backend must support `agentOptions`. Context inheritance and continuation support determine the task and follow-up descriptions. A tool restriction removes both the schema and its `tool:<toolName>` guidance section.
|
|
133
132
|
|
|
134
133
|
#### Token effect
|
|
135
134
|
|
|
136
|
-
Fixed schema cost per parent request; model selection adds three parameters. Each
|
|
135
|
+
Fixed schema cost per parent request; model selection adds three parameters. Each tool instance adds one schema and one short system-prompt section.
|
|
137
136
|
|
|
138
137
|
#### KV Cache effect
|
|
139
138
|
|
|
@@ -157,45 +156,45 @@ The schema is prefix-stable across adapter registration and catalog changes. Eac
|
|
|
157
156
|
|
|
158
157
|
#### What the model sees
|
|
159
158
|
|
|
160
|
-
|
|
159
|
+
Visible delegation tools share one guidance paragraph, listing tools in name order and instructing the model to start independent delegations together and keep working while they run. Hidden or unavailable tools are omitted; no guidance appears when none are visible. With both `subagent` and `subagent_fork` visible, the text is:
|
|
161
160
|
|
|
162
161
|
##### Tool-guidance section
|
|
163
162
|
|
|
164
163
|
```markdown
|
|
165
|
-
Start independent subagent
|
|
164
|
+
Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.
|
|
166
165
|
```
|
|
167
166
|
|
|
168
167
|
#### Token effect
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
At most one short delegation paragraph per parent request, listing the tool names visible to that request.
|
|
171
170
|
|
|
172
171
|
#### KV Cache effect
|
|
173
172
|
|
|
174
|
-
Prefix-stable while the
|
|
173
|
+
Prefix-stable while the visible tool names are unchanged; adding or removing a visible tool changes the paragraph.
|
|
175
174
|
|
|
176
|
-
###
|
|
175
|
+
### Start result
|
|
177
176
|
|
|
178
177
|
#### What the model sees
|
|
179
178
|
|
|
180
|
-
The call retains the description and prompt. Success
|
|
179
|
+
The call retains the task description and prompt. Success returns `started subagent <childId>`; startup rejection returns an error. Child execution details are delivered separately from this acknowledgement.
|
|
181
180
|
|
|
182
181
|
#### Token effect
|
|
183
182
|
|
|
184
|
-
The prompt and
|
|
183
|
+
The prompt and acknowledgement remain in parent history until compaction; child working context remains in the child.
|
|
185
184
|
|
|
186
185
|
#### KV Cache effect
|
|
187
186
|
|
|
188
187
|
Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
|
|
189
188
|
|
|
190
|
-
###
|
|
189
|
+
### Completion delivery
|
|
191
190
|
|
|
192
191
|
#### What the model sees
|
|
193
192
|
|
|
194
|
-
|
|
193
|
+
Answer delivery follows the managed delegation rules above. The returned child id identifies subsequent control and catalog operations; only backends with continuation support accept follow-up messages.
|
|
195
194
|
|
|
196
195
|
#### Token effect
|
|
197
196
|
|
|
198
|
-
|
|
197
|
+
Messages and completion notices append to parent history independently of the start acknowledgement. The tool result itself contains no final output.
|
|
199
198
|
|
|
200
199
|
#### KV Cache effect
|
|
201
200
|
|
|
@@ -208,8 +207,7 @@ Append-only; newly visible content follows the reusable request prefix and does
|
|
|
208
207
|
|
|
209
208
|
These limits define what this tool does not return or enforce; they are current package constraints.
|
|
210
209
|
|
|
211
|
-
- **
|
|
212
|
-
- **Duplicate names across waiting one-shot instances are detected late** (`TODO(subagent-dup-toolname)`) — continuable instances reserve their prompt-section name during plugin application, but preventing provider-registration rollback for waiting one-shot instances requires a registry of intended names.
|
|
210
|
+
- **This tool does not wait for results** — use the completion notice or child messages. Programmatic result waiting belongs to the subagent service.
|
|
213
211
|
- **Shipped fork tools cannot select a child LLM route** — they inherit the parent's provider and model to keep the copied conversation prefix eligible for KV Cache reuse. Re-enable selection only when route changes preserve reuse or expose a bounded recomputation cost.
|
|
214
212
|
- **Non-routing child policy is fixed per instance** — another persona, tool filter, or depth cap requires another distinctly named tool. LLM selection requires an enabled per-Session preference and a provider that advertises `agentOptions`; both in-process providers and DSH SDK advertise it, while ACP, Codex, and Claude Code reject it rather than ignore it.
|
|
215
213
|
|
package/README.zh.md
CHANGED
|
@@ -9,7 +9,7 @@ kind: "package-reference"
|
|
|
9
9
|
|
|
10
10
|
## 概述
|
|
11
11
|
|
|
12
|
-
使用本包可为 agent
|
|
12
|
+
使用本包可为 agent 提供具名工具,把工作委派给配置的后端。每次调用都会启动受管理的 activation 并返回子任务 id;运行时负责完成通知与清理。本地子任务支持消息和恢复,外部后端执行一次任务,并通过完成通知返回最终回答。受支持的后端可以公开获准的子级 LLM 路由。每个实例均可设置子 agent 的 persona、工具权限与深度限制。
|
|
13
13
|
|
|
14
14
|
## 目录
|
|
15
15
|
|
|
@@ -25,6 +25,8 @@ kind: "package-reference"
|
|
|
25
25
|
<a id="use-this-package"></a>
|
|
26
26
|
## 使用本包
|
|
27
27
|
|
|
28
|
+
可选参数 `cwd` 选择子级的初始工作目录。相对路径以调用者当前目录解析;省略时继承该目录。调用者切换目录时,已有子级保留自己的目录。
|
|
29
|
+
|
|
28
30
|
每个委派目标挂载一个实例,且每个实例的 `toolName` 必须不同。工具与其提供方同时存在、同时消失,因此同级加载顺序与提供方重新加载都不会让工具悬空。
|
|
29
31
|
|
|
30
32
|
### 最小配置
|
|
@@ -45,8 +47,6 @@ kind: "package-reference"
|
|
|
45
47
|
| `provider` | 必填 | `ctx.subagents` 上的提供方名称(如 `spawn`、`fork`、`acp`) |
|
|
46
48
|
| `toolName` | `subagent` | 面向模型的工具名称;每个已加载实例必须不同 |
|
|
47
49
|
| `modelSelectionSettings` | `false` | 为每个顶层 Session 读取宿主的精确路由授权偏好;常驻 preset 观察匹配 Session,直接 Agent setup 则显式传入其 Session;要求提供方支持 `agentOptions` |
|
|
48
|
-
| `enableRunInBackground` | `true` | 公开 `run_in_background`;禁用时也会拒绝强制后台调用 |
|
|
49
|
-
| `backgroundMode` | `one-shot` | 后台策略:`one-shot` 默认前台调用;`continuable` 默认后台调用,并要求提供方具备 `prepareContinuable` 能力 |
|
|
50
50
|
| `agentOptions` | — | 配置的子级 `provider`、`model`、适配器所有的 `reasoningEffort` 与正整数 `maxTokens` 默认值;要求提供方支持 `agentOptions`,并会覆盖提供方持有的路由默认值 |
|
|
51
51
|
| `persona` | — | 每个子 agent 独立的 persona;要求提供方具备 `persona` 能力 |
|
|
52
52
|
| `toolFilter` | — | 每个子 agent 独立的全局工具限制;要求提供方具备 `toolFilter` 能力 |
|
|
@@ -54,11 +54,11 @@ kind: "package-reference"
|
|
|
54
54
|
|
|
55
55
|
生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-tool-subagent)是每个受支持字段及其 JSDoc 的穷尽式真源。
|
|
56
56
|
|
|
57
|
-
###
|
|
57
|
+
### 受管理的委派
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
运行时接受子任务后,每次调用都会返回 `started subagent <childId>`,不等待子任务结果。activation 独立于已完成的工具调用拥有这项工作;运行时发送完成通知并释放执行资源。
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
所有后端的完成通知都会附带最终回答。本地 Spawn 和 Fork 子任务还可以发送消息,在活跃期间通过 `send_message` 接受更多工作,或在结束后恢复。Codex、Claude Code、ACP 与 DSH SDK 后端不接受后续消息。
|
|
62
62
|
|
|
63
63
|
`maxDepth` 限制递归深度(`0` 禁止委派);省略时,每次委派读取 Host 当前的 `subagent.maxDepth` 设置,初始值为 `1`。数值深度要求提供方具备 `depthLimit` 能力;`'provider-managed'` 把预算留给进程外提供方。当提供方支持时,`persona` 与 `toolFilter` 会配置每个子 agent;工具在达到上限时仍然可见——每次尝试启动都会检查调用 agent 的当前深度,被拒绝时返回出错的工具结果。
|
|
64
64
|
|
|
@@ -82,13 +82,13 @@ kind: "package-reference"
|
|
|
82
82
|
|
|
83
83
|
一个实例就是一个提供方加一个工具名称。插件镜像提供方生命周期:具名提供方出现时注册工具,提供方离开时释放工具,因此同级加载顺序与 HMR 替换不会让工具悬空。直接 Agent setup 显式传入尚未发布的 Session,并在发布前等待安装完成。由设置控制的常驻 preset 通过 `agent/created` 接收每个匹配 Agent,从其 Session 选择策略,并等待通过其 Context 发起的安装;安装失败会拒绝创建。提供方无法执行的数值型 `maxDepth` 或已配置 LLM 选择会在挂载时失败,而不是在首次委派时失败。每个工具作用域内最多一个实例可以拥有模型选择,因为 `list_subagent_models` 使用全局名称。
|
|
84
84
|
|
|
85
|
-
###
|
|
85
|
+
### Activation 所有权
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
工具调用 `ctx.subagents.startActivation()`,并选择向父任务交付。运行时拥有启动取消、执行、结果汇报与清理。启动失败产生出错的工具结果;发布后的失败通过完成通知到达,运行时保留诊断和部分输出。
|
|
88
88
|
|
|
89
|
-
###
|
|
89
|
+
### 结果确认
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
规范工具结果为 `{ kind: 'activation', subagentId }`。其中没有执行 Promise 或最终输出;需要等待结果的程序调用方直接使用 subagent 服务。
|
|
92
92
|
|
|
93
93
|
### 随上下文变化的措辞
|
|
94
94
|
|
|
@@ -98,7 +98,7 @@ kind: "package-reference"
|
|
|
98
98
|
|
|
99
99
|
| 文件 | 职责 |
|
|
100
100
|
|---|---|
|
|
101
|
-
| [`src/index.ts`](src/index.ts) |
|
|
101
|
+
| [`src/index.ts`](src/index.ts) | 工具注册、提供方生命周期镜像、activation 请求 |
|
|
102
102
|
| [`src/model-selection.ts`](src/model-selection.ts) | 请求/配置合并与实时 LLM 路由预检 |
|
|
103
103
|
| [`src/model-selection-settings.ts`](src/model-selection-settings.ts) | 为新 Session 读取的宿主所有 opt-in 设置 |
|
|
104
104
|
| [`src/model-selection-state.ts`](src/model-selection-state.ts) | 记录并继承已读取决定的 Session 事件 |
|
|
@@ -113,11 +113,10 @@ kind: "package-reference"
|
|
|
113
113
|
|
|
114
114
|
当包级约定不够用时阅读以下页面;它们从工具运行时行为进入它所委派其上的 seam,以及相邻的子 agent 工具。
|
|
115
115
|
|
|
116
|
-
- [Subagent 子系统](../../../docs/subsystems/subagent.zh.md)
|
|
116
|
+
- [Subagent 子系统](../../../docs/subsystems/subagent.zh.md)——提供方、activation、结果与继续执行。
|
|
117
117
|
- [dsh-tool-subagent-control](../tool-subagent-control/README.zh.md)——可继续子 agent 的消息、中断与列表工具。
|
|
118
|
-
- [生成工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-subagent)——默认 schema
|
|
118
|
+
- [生成工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-subagent)——默认 schema 与后端相关的措辞。
|
|
119
119
|
- [生成配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-tool-subagent)——每个受支持配置字段。
|
|
120
|
-
- [后台优先的可继续委派](../../../.agents/notes/archived/feature/2026-08-11-background-first-continuable-delegation.md)——可继续工作为何默认在后台运行。
|
|
121
120
|
- [历史模型选择 subagent 路由](../../../.agents/notes/archived/feature/2026-08-18-model-selected-subagent-routes.md)——选择策略、继承、发现与 fork 限制。
|
|
122
121
|
|
|
123
122
|
-----
|
|
@@ -129,11 +128,11 @@ kind: "package-reference"
|
|
|
129
128
|
|
|
130
129
|
#### 模型看到什么
|
|
131
130
|
|
|
132
|
-
|
|
131
|
+
提供方存在时,以配置的工具名称公开生成的默认 [`subagent` schema](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-subagent)。启用的 Session 策略会添加 `provider`、`model`、`reasoning_effort` 和路由指引;后端必须支持 `agentOptions`。上下文继承和继续执行能力决定任务与后续消息的描述。工具限制会同时移除 schema 及其 `tool:<toolName>` 指引 section。
|
|
133
132
|
|
|
134
133
|
#### Token 影响
|
|
135
134
|
|
|
136
|
-
每个父级请求支付固定的 schema
|
|
135
|
+
每个父级请求支付固定的 schema 成本;模型选择增加三个参数。每个工具实例增加一个 schema 和一个简短的系统提示词 section。
|
|
137
136
|
|
|
138
137
|
#### KV Cache 影响
|
|
139
138
|
|
|
@@ -157,45 +156,45 @@ Session 携带策略的 settings 控制实例会公开子级 LLM 选择字段与
|
|
|
157
156
|
|
|
158
157
|
#### 模型看到什么
|
|
159
158
|
|
|
160
|
-
|
|
159
|
+
可见的委派工具共享一段指导,列出按名称排序的工具,指示模型一起启动相互独立的委派,并在它们运行时继续工作。隐藏或不可用的工具不列入其中;没有可见工具时,不输出指导。`subagent` 和 `subagent_fork` 都可见时,文本为:
|
|
161
160
|
|
|
162
161
|
##### 工具指导 section
|
|
163
162
|
|
|
164
163
|
```markdown
|
|
165
|
-
Start independent subagent
|
|
164
|
+
Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.
|
|
166
165
|
```
|
|
167
166
|
|
|
168
167
|
#### Token 影响
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
每个父级请求最多包含一段简短的委派指导,列出该请求可见的工具名。
|
|
171
170
|
|
|
172
171
|
#### KV Cache 影响
|
|
173
172
|
|
|
174
|
-
|
|
173
|
+
可见工具名不变时,前缀保持稳定;增加或移除可见工具会更改这段指导。
|
|
175
174
|
|
|
176
|
-
###
|
|
175
|
+
### 启动结果
|
|
177
176
|
|
|
178
177
|
#### 模型看到什么
|
|
179
178
|
|
|
180
|
-
|
|
179
|
+
调用保留任务描述与提示词。成功返回 `started subagent <childId>`;启动被拒绝则返回错误。子任务执行详情独立于这条确认交付。
|
|
181
180
|
|
|
182
181
|
#### Token 影响
|
|
183
182
|
|
|
184
|
-
|
|
183
|
+
提示词与确认保留在父级历史中,直到上下文压缩;子任务工作上下文留在子任务中。
|
|
185
184
|
|
|
186
185
|
#### KV Cache 影响
|
|
187
186
|
|
|
188
187
|
仅追加;新增可见内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
|
|
189
188
|
|
|
190
|
-
###
|
|
189
|
+
### 完成交付
|
|
191
190
|
|
|
192
191
|
#### 模型看到什么
|
|
193
192
|
|
|
194
|
-
|
|
193
|
+
回答投递遵循上文的受管理委派规则。返回的子任务 id 用于后续控制与目录操作;只有支持继续执行的后端才接受后续消息。
|
|
195
194
|
|
|
196
195
|
#### Token 影响
|
|
197
196
|
|
|
198
|
-
|
|
197
|
+
消息与完成通知独立于启动确认追加到父级历史。工具结果本身不包含最终输出。
|
|
199
198
|
|
|
200
199
|
#### KV Cache 影响
|
|
201
200
|
|
|
@@ -208,8 +207,7 @@ Start independent subagent delegations together in one assistant message and con
|
|
|
208
207
|
|
|
209
208
|
这些限制说明本工具不返回或不强制执行什么;它们是当前包约束。
|
|
210
209
|
|
|
211
|
-
-
|
|
212
|
-
- **等待中的一次性实例较晚才发现重复名称**(`TODO(subagent-dup-toolname)`)——可继续实例会在插件应用期间预留提示词 section 名称,但若要阻止等待中的一次性实例回滚提供方注册,仍需要一份预期名称注册表。
|
|
210
|
+
- **本工具不等待结果**——使用完成通知或子任务消息。程序化结果等待由 subagent 服务提供。
|
|
213
211
|
- **随附 fork 工具不能选择子级 LLM 路由**——它们继承父级提供方与模型,使复制的对话前缀仍有资格复用 KV Cache。仅当路由变更能保留复用或公开有界重算成本时,才重新启用选择。
|
|
214
212
|
- **非路由子 agent 策略按实例固定**——另一个 persona、工具过滤器或深度上限需要另一个名称不同的工具。LLM 选择要求启用逐 Session 偏好,且提供方必须声明 `agentOptions`;两个进程内提供方和 DSH SDK 会声明该能力,而 ACP、Codex 与 Claude Code 会拒绝它,而不是忽略它。
|
|
215
213
|
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import z from "@deepseek-ai/schemastery";
|
|
|
2
2
|
import { scopeChainOf, scopeOf } from "@deepseek-ai/dsh-scope";
|
|
3
3
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
4
|
import { SessionSeq } from "@deepseek-ai/dsh-session";
|
|
5
|
-
import { assertSubagentMaxDepth, parentAgentOptionsForDelegation
|
|
5
|
+
import { assertSubagentMaxDepth, parentAgentOptionsForDelegation } from "@deepseek-ai/dsh-subagent";
|
|
6
6
|
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
7
7
|
import { z as z$1 } from "zod";
|
|
8
8
|
z.object({
|
|
@@ -236,10 +236,8 @@ function recordSubagentModelSelection(projections, session, allowedModels) {
|
|
|
236
236
|
/**
|
|
237
237
|
* Model-facing delegation through one configured `ctx.subagents` provider.
|
|
238
238
|
* Provider lifecycle controls tool registration and context-sensitive schema
|
|
239
|
-
* wording.
|
|
240
|
-
*
|
|
241
|
-
* calls own a plain Task, while continuable calls use
|
|
242
|
-
* `ctx.subagents.startContinuable()`.
|
|
239
|
+
* wording. Every delegation starts a managed activation and returns its child
|
|
240
|
+
* id; the subagent runtime owns result delivery and resource cleanup.
|
|
243
241
|
* @module @deepseek-ai/dsh-tool-subagent
|
|
244
242
|
*/
|
|
245
243
|
const name = "tool-subagent";
|
|
@@ -249,12 +247,11 @@ const inject = [
|
|
|
249
247
|
"systemPrompt",
|
|
250
248
|
"sessionProjections"
|
|
251
249
|
];
|
|
250
|
+
const delegationTools = /* @__PURE__ */ new Set();
|
|
252
251
|
const Config = z.object({
|
|
253
252
|
provider: z.string().required(),
|
|
254
253
|
toolName: z.string().default("subagent"),
|
|
255
254
|
modelSelectionSettings: z.boolean().default(false),
|
|
256
|
-
enableRunInBackground: z.boolean().default(true),
|
|
257
|
-
backgroundMode: z.union(["one-shot", "continuable"]).default("one-shot"),
|
|
258
255
|
agentOptions: z.object({
|
|
259
256
|
provider: z.string(),
|
|
260
257
|
model: z.string(),
|
|
@@ -268,67 +265,6 @@ const Config = z.object({
|
|
|
268
265
|
}).default(void 0),
|
|
269
266
|
maxDepth: z.union([z.natural().max(Number.MAX_SAFE_INTEGER), z.const("provider-managed")])
|
|
270
267
|
});
|
|
271
|
-
/** Render text blocks from the canonical JSON block array without trusting arbitrary values. */
|
|
272
|
-
function outputValueText(values) {
|
|
273
|
-
return values.filter((value) => typeof value === "object" && value !== null && !Array.isArray(value) && value.type === "text" && typeof value.text === "string").map((value) => value.text).join("");
|
|
274
|
-
}
|
|
275
|
-
/** Settle pending startup without rejecting the task producer contract. */
|
|
276
|
-
async function settleStart(start, signal) {
|
|
277
|
-
try {
|
|
278
|
-
return await settleRun(await start);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
return signal.aborted && !(error instanceof AggregateError) ? { status: "killed" } : {
|
|
281
|
-
status: "failed",
|
|
282
|
-
detail: String(error)
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
/** A non-`completed` stop reason means the child did not finish cleanly. */
|
|
287
|
-
function stopReasonError(result) {
|
|
288
|
-
switch (result.stopReason) {
|
|
289
|
-
case "completed": return;
|
|
290
|
-
case "aborted": return "subagent run was cancelled";
|
|
291
|
-
case "error": return "subagent run failed";
|
|
292
|
-
case "max-tokens": return "subagent run hit its token limit before finishing";
|
|
293
|
-
case "refusal": return "subagent declined the task";
|
|
294
|
-
default: return `subagent run ended abnormally (${String(result.stopReason)})`;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Append provider-authored failure detail and the child's preserved partial
|
|
299
|
-
* answer to a stop-reason error, keeping diagnostic text separate from the
|
|
300
|
-
* child's assistant output.
|
|
301
|
-
* @param error - the stop-reason headline.
|
|
302
|
-
* @param result - the child's terminal result.
|
|
303
|
-
* @returns the headline, diagnostic, and partial text that are present.
|
|
304
|
-
*/
|
|
305
|
-
function withDiagnosticAndPartialText(error, result) {
|
|
306
|
-
const diagnostic = result.diagnostic === void 0 ? "" : `\nDiagnostic: ${result.diagnostic}`;
|
|
307
|
-
const text = result.output.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
308
|
-
return `${error}${diagnostic}${text.length === 0 ? "" : `\nPartial output before the run ended:\n${text}`}`;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Collect and release one foreground run without letting disposal replace an
|
|
312
|
-
* independent result failure.
|
|
313
|
-
*/
|
|
314
|
-
async function settleForegroundRun(run) {
|
|
315
|
-
const [execution] = await Promise.allSettled([run.result.then((result) => {
|
|
316
|
-
const error = stopReasonError(result);
|
|
317
|
-
if (error !== void 0) throw new Error(withDiagnosticAndPartialText(error, result));
|
|
318
|
-
return {
|
|
319
|
-
kind: "foreground",
|
|
320
|
-
runId: run.id,
|
|
321
|
-
output: result.output
|
|
322
|
-
};
|
|
323
|
-
})]);
|
|
324
|
-
const [disposal] = await Promise.allSettled([Promise.resolve().then(() => run.dispose())]);
|
|
325
|
-
if (execution.status === "rejected") {
|
|
326
|
-
if (disposal.status === "rejected") throw new AggregateError([execution.reason, disposal.reason], `subagent run failed: ${String(execution.reason)}; dispose failed: ${String(disposal.reason)}`);
|
|
327
|
-
throw execution.reason;
|
|
328
|
-
}
|
|
329
|
-
if (disposal.status === "rejected") throw disposal.reason;
|
|
330
|
-
return execution.value;
|
|
331
|
-
}
|
|
332
268
|
/**
|
|
333
269
|
* Model-facing wording from the provider's conversation-history descriptor
|
|
334
270
|
* ({@link SubagentProvider.inheritsParentContext}).
|
|
@@ -351,14 +287,6 @@ function providerWording(inheritsConversation) {
|
|
|
351
287
|
promptDescription: "The complete, self-contained task for the subagent. It does not share this conversation's context, so include everything it needs."
|
|
352
288
|
};
|
|
353
289
|
}
|
|
354
|
-
/** Resolve the model's optional scheduling request into one execution route. */
|
|
355
|
-
function resolveDelegationRun(request, options) {
|
|
356
|
-
if (!options.backgroundEnabled) {
|
|
357
|
-
if (request.run_in_background === true) throw new Error("run_in_background is disabled for this tool instance (enableRunInBackground: false)");
|
|
358
|
-
return { runInBackground: false };
|
|
359
|
-
}
|
|
360
|
-
return { runInBackground: request.run_in_background ?? options.continuable };
|
|
361
|
-
}
|
|
362
290
|
/**
|
|
363
291
|
* Install one delegation-tool composition.
|
|
364
292
|
* @param ctx - Context that owns the registrations.
|
|
@@ -368,8 +296,6 @@ function resolveDelegationRun(request, options) {
|
|
|
368
296
|
function apply(ctx, config, session) {
|
|
369
297
|
if (config.maxDepth !== "provider-managed") assertSubagentMaxDepth(config.maxDepth);
|
|
370
298
|
if (config.toolFilter !== void 0 && config.toolFilter.allow === void 0 && config.toolFilter.deny === void 0) throw new Error("tool-subagent: `toolFilter` is configured but names neither `allow` nor `deny` — remove the key or fill the filter");
|
|
371
|
-
const backgroundEnabled = config.enableRunInBackground !== false;
|
|
372
|
-
const continuable = (config.backgroundMode ?? "one-shot") === "continuable";
|
|
373
299
|
const toolName = config.toolName ?? "subagent";
|
|
374
300
|
const modelSelectionCapable = config.modelSelectionSettings === true;
|
|
375
301
|
ctx.sessionProjections.register(subagentModelSelectionProjectionDefinition);
|
|
@@ -377,7 +303,6 @@ function apply(ctx, config, session) {
|
|
|
377
303
|
if (ctx.subagents.resolveMaxDepth(config.maxDepth) !== void 0 && !subagentProvider.capabilities.depthLimit) throw new Error(`tool-subagent: provider "${subagentProvider.name}" cannot enforce maxDepth (no depthLimit capability) — set maxDepth: 'provider-managed' to leave the recursion budget to the provider`);
|
|
378
304
|
if (config.agentOptions !== void 0 && !subagentProvider.capabilities.agentOptions) throw new Error(`tool-subagent: provider "${subagentProvider.name}" does not support child agentOptions`);
|
|
379
305
|
if (modelSelectionCapable && !subagentProvider.capabilities.agentOptions) throw new Error(`tool-subagent: provider "${subagentProvider.name}" does not support child model selection`);
|
|
380
|
-
if (continuable && subagentProvider.prepareContinuable === void 0) throw new Error(`tool-subagent: provider "${subagentProvider.name}" does not support \`backgroundMode: continuable\``);
|
|
381
306
|
};
|
|
382
307
|
ctx.on("subagent/provider-added", (subagentProvider) => {
|
|
383
308
|
if (subagentProvider.name === config.provider) assertSubagentProviderConfiguration(subagentProvider);
|
|
@@ -393,173 +318,114 @@ function apply(ctx, config, session) {
|
|
|
393
318
|
const wording = providerWording(subagentProvider.inheritsParentContext);
|
|
394
319
|
const providerRouteDefaults = subagentProvider.agentRouteDefaults;
|
|
395
320
|
const choiceDescription = !modelSelectionEnabled ? "" : (providerRouteDefaults !== void 0 ? " Child LLM selection is optional. Omit `provider`, `model`, and `reasoning_effort` to use configured child defaults and this provider's route defaults. Supply `provider` and `model` together after using `list_subagent_models` to inspect advertised routes and efforts. Changing the effective route without naming an effort uses the selected model's default effort." : " Child LLM selection is optional. Omit `provider`, `model`, and `reasoning_effort` to use configured child defaults and inherit compatible missing values from the parent Agent. Supply `provider` and `model` together after using `list_subagent_models` to inspect advertised routes and efforts. Changing the effective route without naming an effort uses the selected model's default effort.") + (subagentProvider.inheritsParentContext ? " Changing the route can prevent provider-side reuse of the inherited conversation prefix." : "");
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
description:
|
|
321
|
+
const definition = defineTool({
|
|
322
|
+
name: toolName,
|
|
323
|
+
description: wording.description + " This tool starts an independently managed subagent and immediately returns its id. The runtime notifies you when it finishes." + (subagentProvider.prepareContinuable !== void 0 ? " The child reports results with `send_message`; use `send_message` to steer it while running or continue its conversation after it finishes." : " The completion notice includes its final answer. This backend does not accept follow-up messages.") + choiceDescription,
|
|
324
|
+
parameters: {
|
|
325
|
+
cwd: {
|
|
326
|
+
type: "string",
|
|
327
|
+
description: "Initial child working directory. Relative paths use your current directory; omitted inherits it. Later directory changes in either agent are independent."
|
|
328
|
+
},
|
|
329
|
+
description: {
|
|
330
|
+
type: "string",
|
|
331
|
+
required: true,
|
|
332
|
+
description: "A short (3-5 word) description of the delegated task, for display."
|
|
333
|
+
},
|
|
334
|
+
prompt: {
|
|
335
|
+
type: "string",
|
|
336
|
+
required: true,
|
|
337
|
+
description: wording.promptDescription
|
|
338
|
+
},
|
|
339
|
+
...modelSelectionEnabled ? {
|
|
340
|
+
provider: {
|
|
403
341
|
type: "string",
|
|
404
|
-
|
|
405
|
-
description: "A short (3-5 word) description of the delegated task, for display."
|
|
342
|
+
description: providerRouteDefaults !== void 0 ? "LLM provider route for the child. Supply together with model; omit both to use configured child defaults or this provider's route defaults." : "LLM provider route for the child. Supply together with model; omit both to use configured child defaults or inherit the parent route."
|
|
406
343
|
},
|
|
407
|
-
|
|
344
|
+
model: {
|
|
408
345
|
type: "string",
|
|
409
|
-
|
|
410
|
-
description: wording.promptDescription
|
|
346
|
+
description: providerRouteDefaults !== void 0 ? "Model id interpreted by provider. Supply together with provider; omit both to use configured child defaults or this provider's route defaults." : "Model id interpreted by provider. Supply together with provider; omit both to use configured child defaults or inherit the parent route."
|
|
411
347
|
},
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
348
|
+
reasoning_effort: {
|
|
349
|
+
type: "string",
|
|
350
|
+
description: providerRouteDefaults !== void 0 ? "Adapter-owned reasoning effort for the effective child route. Omit to use a compatible configured effort or the selected model's default." : "Adapter-owned reasoning effort for the effective child route. Omit to inherit a compatible configured/parent effort or use a newly selected model's default."
|
|
351
|
+
}
|
|
352
|
+
} : {}
|
|
353
|
+
},
|
|
354
|
+
output: {
|
|
355
|
+
schema: {
|
|
356
|
+
type: "object",
|
|
357
|
+
additionalProperties: false,
|
|
358
|
+
properties: {
|
|
359
|
+
kind: {
|
|
418
360
|
type: "string",
|
|
419
|
-
|
|
361
|
+
required: true,
|
|
362
|
+
const: "activation"
|
|
420
363
|
},
|
|
421
|
-
|
|
364
|
+
subagentId: {
|
|
422
365
|
type: "string",
|
|
423
|
-
|
|
366
|
+
required: true
|
|
424
367
|
}
|
|
425
|
-
}
|
|
426
|
-
...backgroundEnabled ? { run_in_background: {
|
|
427
|
-
type: "boolean",
|
|
428
|
-
description: continuable ? "Defaults to true. Set false only when your next action depends on the result." : "Run as a background job and return its id (collect with job_output, stop with job_kill). Defaults to false."
|
|
429
|
-
} } : {}
|
|
368
|
+
}
|
|
430
369
|
},
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
required: true
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
type: "object",
|
|
465
|
-
additionalProperties: false,
|
|
466
|
-
properties: {
|
|
467
|
-
kind: {
|
|
468
|
-
type: "string",
|
|
469
|
-
required: true,
|
|
470
|
-
const: "foreground"
|
|
471
|
-
},
|
|
472
|
-
runId: {
|
|
473
|
-
type: "string",
|
|
474
|
-
required: true
|
|
475
|
-
},
|
|
476
|
-
output: {
|
|
477
|
-
type: "array",
|
|
478
|
-
required: true,
|
|
479
|
-
items: { type: "json" }
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
] },
|
|
484
|
-
render: (_args, value) => [{
|
|
370
|
+
render: (_args, value) => [{
|
|
371
|
+
type: "text",
|
|
372
|
+
text: `started subagent ${value.subagentId}`
|
|
373
|
+
}]
|
|
374
|
+
},
|
|
375
|
+
isConcurrencySafe: () => true,
|
|
376
|
+
async execute(args, exec) {
|
|
377
|
+
const parent = exec.agent;
|
|
378
|
+
if (!parent) throw new Error("subagent tool requires a calling agent (exec.agent was undefined)");
|
|
379
|
+
const modelRequest = args;
|
|
380
|
+
const parentOptions = parentAgentOptionsForDelegation(parent);
|
|
381
|
+
const requiresRoutePreflight = hasDelegationModelRequest(modelRequest) || hasConfiguredLlmSelection(config.agentOptions);
|
|
382
|
+
const requestedChildAgentOptions = requestedAgentOptions(parentOptions, requiresRoutePreflight && providerRouteDefaults !== void 0 ? {
|
|
383
|
+
...providerRouteDefaults,
|
|
384
|
+
...config.agentOptions
|
|
385
|
+
} : config.agentOptions, modelRequest, modelSelectionEnabled);
|
|
386
|
+
assertAllowedModelSelection(modelSelectionPolicy, parentOptions, requestedChildAgentOptions, modelRequest);
|
|
387
|
+
if (requiresRoutePreflight) {
|
|
388
|
+
const llm = runtimeCtx.get("llm");
|
|
389
|
+
if (llm === void 0) throw new Error("cannot resolve the selected child LLM route because the `llm` service is unavailable");
|
|
390
|
+
await preflightChildLlmRoute(llm, parentOptions, requestedChildAgentOptions, exec.signal, providerRouteDefaults === void 0);
|
|
391
|
+
if (runtimeCtx.subagents.getProvider(config.provider) !== subagentProvider) throw new Error(`subagent provider "${config.provider}" changed while resolving the child LLM route; retry the delegation`);
|
|
392
|
+
}
|
|
393
|
+
exec.signal.throwIfAborted();
|
|
394
|
+
const maxDepth = runtimeCtx.subagents.resolveMaxDepth(config.maxDepth);
|
|
395
|
+
const request = {
|
|
396
|
+
...args.cwd === void 0 ? {} : { cwd: args.cwd },
|
|
397
|
+
prompt: [{
|
|
485
398
|
type: "text",
|
|
486
|
-
text:
|
|
487
|
-
}]
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
...config.agentOptions
|
|
499
|
-
} : config.agentOptions, modelRequest, modelSelectionEnabled);
|
|
500
|
-
assertAllowedModelSelection(modelSelectionPolicy, parentOptions, requestedChildAgentOptions, modelRequest);
|
|
501
|
-
if (requiresRoutePreflight) {
|
|
502
|
-
const llm = runtimeCtx.get("llm");
|
|
503
|
-
if (llm === void 0) throw new Error("cannot resolve the selected child LLM route because the `llm` service is unavailable");
|
|
504
|
-
await preflightChildLlmRoute(llm, parentOptions, requestedChildAgentOptions, exec.signal, providerRouteDefaults === void 0);
|
|
505
|
-
if (runtimeCtx.subagents.getProvider(config.provider) !== subagentProvider) throw new Error(`subagent provider "${config.provider}" changed while resolving the child LLM route; retry the delegation`);
|
|
506
|
-
}
|
|
507
|
-
exec.signal.throwIfAborted();
|
|
508
|
-
const maxDepth = runtimeCtx.subagents.resolveMaxDepth(config.maxDepth);
|
|
509
|
-
const request = {
|
|
399
|
+
text: args.prompt
|
|
400
|
+
}],
|
|
401
|
+
parent,
|
|
402
|
+
...requestedChildAgentOptions !== void 0 ? { agentOptions: requestedChildAgentOptions } : {},
|
|
403
|
+
...config.persona !== void 0 ? { persona: config.persona } : {},
|
|
404
|
+
...config.toolFilter !== void 0 ? { toolFilter: config.toolFilter } : {},
|
|
405
|
+
...maxDepth !== void 0 ? { maxDepth } : {}
|
|
406
|
+
};
|
|
407
|
+
return {
|
|
408
|
+
kind: "activation",
|
|
409
|
+
subagentId: (await runtimeCtx.subagents.startActivation({
|
|
410
|
+
provider: config.provider,
|
|
510
411
|
label: args.description,
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
provider: config.provider,
|
|
529
|
-
label: args.description,
|
|
530
|
-
request,
|
|
531
|
-
signal: exec.signal
|
|
532
|
-
})).childId
|
|
533
|
-
};
|
|
534
|
-
const jobs = runtimeCtx.get("jobs");
|
|
535
|
-
if (jobs === void 0) throw new Error("background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs");
|
|
536
|
-
return {
|
|
537
|
-
kind: "background",
|
|
538
|
-
jobId: jobs.start({
|
|
539
|
-
kind: "subagent",
|
|
540
|
-
label: args.description,
|
|
541
|
-
owner: parent.id,
|
|
542
|
-
run: () => {
|
|
543
|
-
const controller = new AbortController();
|
|
544
|
-
return {
|
|
545
|
-
cancel: (reason) => {
|
|
546
|
-
controller.abort(reason ?? "background subagent task killed");
|
|
547
|
-
},
|
|
548
|
-
done: settleStart(runtimeCtx.subagents.start(config.provider, {
|
|
549
|
-
...request,
|
|
550
|
-
signal: controller.signal
|
|
551
|
-
}), controller.signal)
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
})
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
return settleForegroundRun(await runtimeCtx.subagents.start(config.provider, {
|
|
558
|
-
...request,
|
|
559
|
-
signal: exec.signal
|
|
560
|
-
}));
|
|
561
|
-
}
|
|
562
|
-
}))
|
|
412
|
+
request,
|
|
413
|
+
signal: exec.signal,
|
|
414
|
+
delivery: "parent"
|
|
415
|
+
})).childId
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
mounted = {
|
|
420
|
+
subagentProvider,
|
|
421
|
+
disposeTool: runtimeCtx.effect(() => {
|
|
422
|
+
const unregister = runtimeCtx.tools.register(definition);
|
|
423
|
+
delegationTools.add(definition);
|
|
424
|
+
return () => {
|
|
425
|
+
delegationTools.delete(definition);
|
|
426
|
+
unregister();
|
|
427
|
+
};
|
|
428
|
+
})
|
|
563
429
|
};
|
|
564
430
|
};
|
|
565
431
|
runtimeCtx.on("subagent/provider-added", (subagentProvider) => {
|
|
@@ -573,10 +439,15 @@ function apply(ctx, config, session) {
|
|
|
573
439
|
const present = runtimeCtx.subagents.getProvider(config.provider);
|
|
574
440
|
if (present !== void 0) mount(present);
|
|
575
441
|
else runtimeCtx.logger.info(`subagent provider "${config.provider}" not registered yet; the "${config.toolName ?? "subagent"}" tool will register when it appears`);
|
|
576
|
-
|
|
442
|
+
runtimeCtx.systemPrompt.section({
|
|
577
443
|
name: `tool:${toolName}`,
|
|
578
444
|
order: runtimeCtx.systemPrompt.getSectionOrder("TOOL_SUBAGENT"),
|
|
579
|
-
text: (context) =>
|
|
445
|
+
text: (context) => {
|
|
446
|
+
if (mounted === void 0) return "";
|
|
447
|
+
const visible = [...delegationTools].filter((tool) => runtimeCtx.tools.get(tool.name, context.scope) === tool).map((tool) => tool.name).sort();
|
|
448
|
+
if (visible[0] !== toolName) return "";
|
|
449
|
+
return `Start independent delegations with ${visible.map((name) => `\`${name}\``).join(" or ")} together in one assistant message and continue useful work while they run.`;
|
|
450
|
+
}
|
|
580
451
|
});
|
|
581
452
|
};
|
|
582
453
|
if (config.modelSelectionSettings !== true) {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Model-facing delegation through one configured `ctx.subagents` provider.
|
|
3
3
|
* Provider lifecycle controls tool registration and context-sensitive schema
|
|
4
|
-
* wording.
|
|
5
|
-
*
|
|
6
|
-
* calls own a plain Task, while continuable calls use
|
|
7
|
-
* `ctx.subagents.startContinuable()`.
|
|
4
|
+
* wording. Every delegation starts a managed activation and returns its child
|
|
5
|
+
* id; the subagent runtime owns result delivery and resource cleanup.
|
|
8
6
|
* @module @deepseek-ai/dsh-tool-subagent
|
|
9
7
|
*/
|
|
10
8
|
import type { Context } from '@deepseek-ai/cordis';
|
|
@@ -27,18 +25,6 @@ export interface Config {
|
|
|
27
25
|
* Session and inherit that decision in its child Sessions.
|
|
28
26
|
*/
|
|
29
27
|
modelSelectionSettings?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Expose `run_in_background` (default true). Disabled instances omit the
|
|
32
|
-
* parameter and reject forced background calls.
|
|
33
|
-
*/
|
|
34
|
-
enableRunInBackground?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Background execution policy (default `one-shot`). `one-shot` defaults calls
|
|
37
|
-
* to foreground; `continuable` defaults them to background, requires a provider
|
|
38
|
-
* with the `prepareContinuable` capability, and returns the durable child id.
|
|
39
|
-
* Follow-up adapters remain independently optional.
|
|
40
|
-
*/
|
|
41
|
-
backgroundMode?: 'one-shot' | 'continuable';
|
|
42
28
|
/**
|
|
43
29
|
* Agent options applied to every child; omitted fields use child-loop defaults.
|
|
44
30
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-tool-subagent",
|
|
3
3
|
"description": "Model-facing subagent delegation tool over the ctx.subagents seam",
|
|
4
|
-
"version": "0.2.1-alpha.
|
|
4
|
+
"version": "0.2.1-alpha.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -32,37 +32,33 @@
|
|
|
32
32
|
],
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@deepseek-ai/dsh-agent": "0.2.1-alpha.
|
|
36
|
-
"@deepseek-ai/dsh-llm": "0.2.1-alpha.
|
|
37
|
-
"@deepseek-ai/dsh-session": "0.2.1-alpha.
|
|
38
|
-
"@deepseek-ai/dsh-session-projection": "0.2.1-alpha.
|
|
39
|
-
"@deepseek-ai/dsh-scope": "0.2.1-alpha.
|
|
40
|
-
"@deepseek-ai/dsh-subagent": "0.2.1-alpha.
|
|
41
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.
|
|
42
|
-
"@deepseek-ai/dsh-
|
|
43
|
-
"@deepseek-ai/dsh-tools": "0.2.1-alpha.1",
|
|
35
|
+
"@deepseek-ai/dsh-agent": "0.2.1-alpha.2",
|
|
36
|
+
"@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
|
|
37
|
+
"@deepseek-ai/dsh-session": "0.2.1-alpha.2",
|
|
38
|
+
"@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2",
|
|
39
|
+
"@deepseek-ai/dsh-scope": "0.2.1-alpha.2",
|
|
40
|
+
"@deepseek-ai/dsh-subagent": "0.2.1-alpha.2",
|
|
41
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2",
|
|
42
|
+
"@deepseek-ai/dsh-tools": "0.2.1-alpha.2",
|
|
44
43
|
"@deepseek-ai/cordis": "~4.0.5-alpha.1"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
46
|
+
"@deepseek-ai/schemastery": "~3.18.5-alpha.1",
|
|
47
|
+
"zod": "^4.4.3"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@deepseek-ai/cordis-plugin-loader": "~1.0.6-alpha.1",
|
|
52
|
-
"@deepseek-ai/dsh-agent": "0.2.1-alpha.
|
|
53
|
-
"@deepseek-ai/dsh-llm": "0.2.1-alpha.
|
|
54
|
-
"@deepseek-ai/dsh-session": "0.2.1-alpha.
|
|
55
|
-
"@deepseek-ai/dsh-scope": "0.2.1-alpha.
|
|
56
|
-
"@deepseek-ai/dsh-session-persistence
|
|
57
|
-
"@deepseek-ai/dsh-
|
|
58
|
-
"@deepseek-ai/dsh-
|
|
59
|
-
"@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.1-alpha.
|
|
60
|
-
"@deepseek-ai/dsh-
|
|
61
|
-
"@deepseek-ai/dsh-
|
|
62
|
-
"@deepseek-ai/dsh-tools": "0.2.1-alpha.1",
|
|
51
|
+
"@deepseek-ai/dsh-agent": "0.2.1-alpha.2",
|
|
52
|
+
"@deepseek-ai/dsh-llm": "0.2.1-alpha.2",
|
|
53
|
+
"@deepseek-ai/dsh-session": "0.2.1-alpha.2",
|
|
54
|
+
"@deepseek-ai/dsh-scope": "0.2.1-alpha.2",
|
|
55
|
+
"@deepseek-ai/dsh-session-persistence": "0.2.1-alpha.2",
|
|
56
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "0.2.1-alpha.2",
|
|
57
|
+
"@deepseek-ai/dsh-subagent": "0.2.1-alpha.2",
|
|
58
|
+
"@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.1-alpha.2",
|
|
59
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.1-alpha.2",
|
|
60
|
+
"@deepseek-ai/dsh-tools": "0.2.1-alpha.2",
|
|
63
61
|
"@deepseek-ai/cordis": "~4.0.5-alpha.1",
|
|
64
|
-
"@deepseek-ai/dsh-session-projection": "0.2.1-alpha.
|
|
65
|
-
"@deepseek-ai/dsh-jobs": "0.2.1-alpha.1",
|
|
66
|
-
"@deepseek-ai/dsh-jobs-local": "0.2.1-alpha.1"
|
|
62
|
+
"@deepseek-ai/dsh-session-projection": "0.2.1-alpha.2"
|
|
67
63
|
}
|
|
68
64
|
}
|