@qlzt/dsh-tool-subagent 0.0.0-stage → 0.2.1-alpha.3
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/LICENSE +21 -0
- package/README.i18n.yaml +121 -0
- package/README.md +221 -2
- package/README.zh.md +222 -0
- package/lib/index.js +533 -0
- package/lib/model-selection-settings.js +68 -0
- package/lib/types/index.d.ts +68 -0
- package/lib/types/list-models.d.ts +10 -0
- package/lib/types/model-selection-settings.d.ts +45 -0
- package/lib/types/model-selection-state.d.ts +48 -0
- package/lib/types/model-selection.d.ts +81 -0
- package/package.json +63 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
|
2
|
+
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
|
3
|
+
# After editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/subagent/tool-subagent/README.md
|
|
5
|
+
/:
|
|
6
|
+
en: c6db6e2344a91be8
|
|
7
|
+
zh: 4febc8331d506a22
|
|
8
|
+
/deepseek-ai-dsh-tool-subagent:
|
|
9
|
+
en: 686fb5136bef0a3b
|
|
10
|
+
zh: d25d6569174a01b5
|
|
11
|
+
/deepseek-ai-dsh-tool-subagent/summary:
|
|
12
|
+
en: 958d2b1c56ac6ec7
|
|
13
|
+
zh: cc1997a9ac09e7a5
|
|
14
|
+
/deepseek-ai-dsh-tool-subagent/table-of-contents:
|
|
15
|
+
en: d152484eb41ac6b4
|
|
16
|
+
zh: 09388d293f9be9cb
|
|
17
|
+
/deepseek-ai-dsh-tool-subagent/use-this-package:
|
|
18
|
+
en: 93f1701f5209ecb5
|
|
19
|
+
zh: 6310fd012400aead
|
|
20
|
+
/deepseek-ai-dsh-tool-subagent/use-this-package/minimal-configuration:
|
|
21
|
+
en: d01d4425bc1875dd
|
|
22
|
+
zh: f3d36c8a1e5ed0fa
|
|
23
|
+
/deepseek-ai-dsh-tool-subagent/use-this-package/managed-delegation:
|
|
24
|
+
en: 42673064ba88a211
|
|
25
|
+
zh: 8fa26285bd649dc9
|
|
26
|
+
/deepseek-ai-dsh-tool-subagent/use-this-package/selecting-a-child-llm:
|
|
27
|
+
en: 0d37e3b3957515e4
|
|
28
|
+
zh: ea1a94b2f29e7d9a
|
|
29
|
+
/deepseek-ai-dsh-tool-subagent/understand-the-implementation:
|
|
30
|
+
en: 6ce5f749256a7e6c
|
|
31
|
+
zh: a4f2adb04a70d9cf
|
|
32
|
+
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/design-concept:
|
|
33
|
+
en: 5ceacfed4ea0c648
|
|
34
|
+
zh: 005284534923d854
|
|
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
|
+
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/context-sensitive-wording:
|
|
42
|
+
en: 1733728ac5aa6bb0
|
|
43
|
+
zh: 341ffc6e21a289af
|
|
44
|
+
/deepseek-ai-dsh-tool-subagent/understand-the-implementation/source-map:
|
|
45
|
+
en: 255f6edd3064ff2f
|
|
46
|
+
zh: c3ebfe1e845dfb4b
|
|
47
|
+
/deepseek-ai-dsh-tool-subagent/further-exploration:
|
|
48
|
+
en: fa3c9a967b636afb
|
|
49
|
+
zh: a9ce930a9766d5cb
|
|
50
|
+
/deepseek-ai-dsh-tool-subagent/model-experience:
|
|
51
|
+
en: 215e7ba838619b7b
|
|
52
|
+
zh: a311da3843709f90
|
|
53
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema:
|
|
54
|
+
en: e4c7376d4f29dbd5
|
|
55
|
+
zh: 6b7a9eaf69c9ea53
|
|
56
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema/what-the-model-sees:
|
|
57
|
+
en: 12c872e4264bb6c0
|
|
58
|
+
zh: 20f870a78ebf8d29
|
|
59
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema/token-effect:
|
|
60
|
+
en: 02da2a5e0a75fd91
|
|
61
|
+
zh: fd2d8b11386fc83d
|
|
62
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/tool-schema/kv-cache-effect:
|
|
63
|
+
en: 46f736c6c389052a
|
|
64
|
+
zh: a7765541030e9104
|
|
65
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/model-selection-and-discovery:
|
|
66
|
+
en: a4ca31b9cbacda6b
|
|
67
|
+
zh: 91ac3e0784a14697
|
|
68
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/model-selection-and-discovery/what-the-model-sees:
|
|
69
|
+
en: 1c9dd328eaf96683
|
|
70
|
+
zh: 3be88d3b00f51cfa
|
|
71
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/model-selection-and-discovery/token-effect:
|
|
72
|
+
en: 8137e72f630f0190
|
|
73
|
+
zh: 73b1d9374b6cbccd
|
|
74
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/model-selection-and-discovery/kv-cache-effect:
|
|
75
|
+
en: 7dc47a34d5574fbd
|
|
76
|
+
zh: bd7bd2a4da2f8ae2
|
|
77
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt:
|
|
78
|
+
en: cf78b9dd5596495f
|
|
79
|
+
zh: bd44560f8c2435e8
|
|
80
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/what-the-model-sees:
|
|
81
|
+
en: 5f6611a932063e58
|
|
82
|
+
zh: effededa44c716af
|
|
83
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/what-the-model-sees/tool-guidance-section:
|
|
84
|
+
en: 82b3cd08b3961c98
|
|
85
|
+
zh: bdc2a34bcea16cac
|
|
86
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/token-effect:
|
|
87
|
+
en: 58ee76659f75c73e
|
|
88
|
+
zh: 726c5b789e96677c
|
|
89
|
+
/deepseek-ai-dsh-tool-subagent/model-experience/system-prompt/kv-cache-effect:
|
|
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
|
+
en: f5d5f97a153f7c70
|
|
103
|
+
zh: 3d6bc05b9eadfbc2
|
|
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
|
+
en: f5d5f97a153f7c70
|
|
115
|
+
zh: 3d6bc05b9eadfbc2
|
|
116
|
+
/deepseek-ai-dsh-tool-subagent/known-limitations-and-deferred-work:
|
|
117
|
+
en: 40e99fb684ccffc4
|
|
118
|
+
zh: 08c6820c7a5343e8
|
|
119
|
+
/deepseek-ai-dsh-tool-subagent/known-limitations-and-deferred-work/dev-note:
|
|
120
|
+
en: e67f633dc6fe7773
|
|
121
|
+
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -1,3 +1,222 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
description: "Model-facing subagent delegation tool for users and maintainers configuring, composing, or debugging delegation over a subagent provider."
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# @deepseek-ai/dsh-tool-subagent
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
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
|
+
|
|
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
|
+
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
|
+
|
|
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.
|
|
31
|
+
|
|
32
|
+
### Minimal configuration
|
|
33
|
+
|
|
34
|
+
Load the subagent service, an in-process or remote backend, and this tool; then name the provider. This composition exposes a `subagent` tool that delegates to the `spawn` backend:
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
- name: '@deepseek-ai/dsh-subagent'
|
|
38
|
+
- name: '@deepseek-ai/dsh-subagent-spawn-in-process'
|
|
39
|
+
- name: '@deepseek-ai/dsh-tool-subagent'
|
|
40
|
+
config:
|
|
41
|
+
provider: spawn
|
|
42
|
+
toolName: subagent
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Field | Default | Meaning |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `provider` | required | Provider name on `ctx.subagents` (e.g. `spawn`, `fork`, `acp`) |
|
|
48
|
+
| `toolName` | `subagent` | Model-facing tool name; distinct for every loaded instance |
|
|
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 |
|
|
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
|
+
| `persona` | — | Per-child persona; requires the provider's `persona` capability |
|
|
52
|
+
| `toolFilter` | — | Per-child global-tool restriction; requires the `toolFilter` capability |
|
|
53
|
+
| `maxDepth` | Host setting (`1`) | Absolute delegation-depth cap (`0` forbids delegation); `'provider-managed'` sends no cap to an out-of-process provider |
|
|
54
|
+
|
|
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
|
+
|
|
57
|
+
### Managed delegation
|
|
58
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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
|
+
|
|
65
|
+
### Selecting a child LLM
|
|
66
|
+
|
|
67
|
+
Set `modelSelectionSettings: true` to sample the Host's `subagent-model-selection` preference when each fresh top-level Session is composed. A restored Session without a recorded policy remains disabled, including an explicitly empty restore. When enabled, the non-empty exact provider/model route list is recorded in the Session, inherited by child Sessions, and unchanged by later settings edits. The tool then exposes optional `provider`, `model`, and `reasoning_effort` fields and registers the shared `list_subagent_models` tool. This mode requires a backend that advertises `agentOptions`; both in-process backends and DSH SDK support it, while ACP, Codex, and Claude Code reject it rather than ignore it.
|
|
68
|
+
|
|
69
|
+
A call supplies `provider` and `model` together, or supplies only an effort when configured, parent, or provider-owned defaults provide the route. Static `provider.agentRouteDefaults`, when present, form the provider/model baseline; tool configuration and model fields overlay it before route-aware effort merging and exact-route preflight. Providers without these defaults use compatible values from the parent's latest logged request, then the parent's creation options before its first request, while retaining the configured `maxTokens`. Changing the route without an explicit effort clears the inherited route-owned effort, so the selected model resolves its default. The live LLM adapter validates the effective route before child creation. Catalog membership remains advisory, so a model can use an unlisted id when its adapter accepts it.
|
|
70
|
+
|
|
71
|
+
-----
|
|
72
|
+
|
|
73
|
+
<a id="understand-the-implementation"></a>
|
|
74
|
+
## Understand the implementation
|
|
75
|
+
|
|
76
|
+
<details>
|
|
77
|
+
<summary>Implementation internals — click to expand</summary>
|
|
78
|
+
|
|
79
|
+
This section explains how the tool mirrors provider lifecycle and settles runs; the observable behavior is covered in [Use this package](#use-this-package).
|
|
80
|
+
|
|
81
|
+
### Design concept
|
|
82
|
+
|
|
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
|
+
|
|
85
|
+
### Activation ownership
|
|
86
|
+
|
|
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
|
+
|
|
89
|
+
### Result acknowledgement
|
|
90
|
+
|
|
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
|
+
|
|
93
|
+
### Context-sensitive wording
|
|
94
|
+
|
|
95
|
+
The tool's description derives from `provider.inheritsParentContext`: a fresh child gets "it does not see this conversation" wording, a forked child gets "it does not see the current in-flight turn" wording, so the model never restates or omits context that does not exist.
|
|
96
|
+
|
|
97
|
+
### Source map
|
|
98
|
+
|
|
99
|
+
| File | Role |
|
|
100
|
+
|---|---|
|
|
101
|
+
| [`src/index.ts`](src/index.ts) | Tool registration, provider lifecycle mirroring, activation requests |
|
|
102
|
+
| [`src/model-selection.ts`](src/model-selection.ts) | Request/config merge and live LLM route preflight |
|
|
103
|
+
| [`src/model-selection-settings.ts`](src/model-selection-settings.ts) | Host-owned opt-in setting sampled for new Sessions |
|
|
104
|
+
| [`src/model-selection-state.ts`](src/model-selection-state.ts) | Session event that records and inherits the sampled decision |
|
|
105
|
+
| [`src/list-models.ts`](src/list-models.ts) | `list_subagent_models` runtime discovery tool |
|
|
106
|
+
|
|
107
|
+
</details>
|
|
108
|
+
|
|
109
|
+
-----
|
|
110
|
+
|
|
111
|
+
<a id="further-exploration"></a>
|
|
112
|
+
## Further Exploration
|
|
113
|
+
|
|
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
|
+
|
|
116
|
+
- [Subagent subsystem](../../../docs/subsystems/subagent.md) — providers, activations, results, and continuation.
|
|
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 backend-specific wording.
|
|
119
|
+
- [Generated configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-tool-subagent) — every accepted config field.
|
|
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.
|
|
121
|
+
|
|
122
|
+
-----
|
|
123
|
+
|
|
124
|
+
<a id="model-experience"></a>
|
|
125
|
+
## Model Experience
|
|
126
|
+
|
|
127
|
+
### Tool schema
|
|
128
|
+
|
|
129
|
+
#### What the model sees
|
|
130
|
+
|
|
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.
|
|
132
|
+
|
|
133
|
+
#### Token effect
|
|
134
|
+
|
|
135
|
+
Fixed schema cost per parent request; model selection adds three parameters. Each tool instance adds one schema and one short system-prompt section.
|
|
136
|
+
|
|
137
|
+
#### KV Cache effect
|
|
138
|
+
|
|
139
|
+
Prefix-stable while provider instances and their configuration are unchanged. Adapter catalog changes do not alter the definition; a child route override may prevent a fork child from reusing the inherited parent prefix.
|
|
140
|
+
|
|
141
|
+
### Model selection and discovery
|
|
142
|
+
|
|
143
|
+
#### What the model sees
|
|
144
|
+
|
|
145
|
+
A settings-controlled instance whose Session carries a policy exposes the child LLM selection fields and `list_subagent_models`. Calls reject while the optional `ctx.llm` service is unavailable. Discovery returns only registered providers and advertised models in the exact route policy; an unauthorized provider is rejected before its adapter catalog is called, and an exact lookup must be allowed before it resolves the model's reasoning efforts and default. Execution independently enforces the same policy.
|
|
146
|
+
|
|
147
|
+
#### Token effect
|
|
148
|
+
|
|
149
|
+
One fixed discovery schema is present in enabled compositions. Directory contents enter the transcript only when the model calls the tool.
|
|
150
|
+
|
|
151
|
+
#### KV Cache effect
|
|
152
|
+
|
|
153
|
+
The schema is prefix-stable across adapter registration and catalog changes. Each discovery result is appended after the reusable prefix.
|
|
154
|
+
|
|
155
|
+
### System prompt
|
|
156
|
+
|
|
157
|
+
#### What the model sees
|
|
158
|
+
|
|
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:
|
|
160
|
+
|
|
161
|
+
##### Tool-guidance section
|
|
162
|
+
|
|
163
|
+
```markdown
|
|
164
|
+
Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Token effect
|
|
168
|
+
|
|
169
|
+
At most one short delegation paragraph per parent request, listing the tool names visible to that request.
|
|
170
|
+
|
|
171
|
+
#### KV Cache effect
|
|
172
|
+
|
|
173
|
+
Prefix-stable while the visible tool names are unchanged; adding or removing a visible tool changes the paragraph.
|
|
174
|
+
|
|
175
|
+
### Start result
|
|
176
|
+
|
|
177
|
+
#### What the model sees
|
|
178
|
+
|
|
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.
|
|
180
|
+
|
|
181
|
+
#### Token effect
|
|
182
|
+
|
|
183
|
+
The prompt and acknowledgement remain in parent history until compaction; child working context remains in the child.
|
|
184
|
+
|
|
185
|
+
#### KV Cache effect
|
|
186
|
+
|
|
187
|
+
Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
|
|
188
|
+
|
|
189
|
+
### Completion delivery
|
|
190
|
+
|
|
191
|
+
#### What the model sees
|
|
192
|
+
|
|
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.
|
|
194
|
+
|
|
195
|
+
#### Token effect
|
|
196
|
+
|
|
197
|
+
Messages and completion notices append to parent history independently of the start acknowledgement. The tool result itself contains no final output.
|
|
198
|
+
|
|
199
|
+
#### KV Cache effect
|
|
200
|
+
|
|
201
|
+
Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.
|
|
202
|
+
|
|
203
|
+
## Known Limitations and Deferred Work
|
|
204
|
+
|
|
205
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
These limits define what this tool does not return or enforce; they are current package constraints.
|
|
209
|
+
|
|
210
|
+
- **This tool does not wait for results** — use the completion notice or child messages. Programmatic result waiting belongs to the subagent service.
|
|
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.
|
|
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.
|
|
213
|
+
|
|
214
|
+
<a id="dev-note"></a>
|
|
215
|
+
### Dev Note
|
|
216
|
+
|
|
217
|
+
<details>
|
|
218
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
219
|
+
|
|
220
|
+
None.
|
|
221
|
+
|
|
222
|
+
</details>
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "面向模型的 subagent 委派工具,供用户与维护者配置、组合或排查基于 subagent 提供方的委派。"
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-tool-subagent
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
使用本包可为 agent 提供具名工具,把工作委派给配置的后端。每次调用都会启动受管理的 activation 并返回子任务 id;运行时负责完成通知与清理。本地子任务支持消息和恢复,外部后端执行一次任务,并通过完成通知返回最终回答。受支持的后端可以公开获准的子级 LLM 路由。每个实例均可设置子 agent 的 persona、工具权限与深度限制。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
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
|
+
可选参数 `cwd` 选择子级的初始工作目录。相对路径以调用者当前目录解析;省略时继承该目录。调用者切换目录时,已有子级保留自己的目录。
|
|
29
|
+
|
|
30
|
+
每个委派目标挂载一个实例,且每个实例的 `toolName` 必须不同。工具与其提供方同时存在、同时消失,因此同级加载顺序与提供方重新加载都不会让工具悬空。
|
|
31
|
+
|
|
32
|
+
### 最小配置
|
|
33
|
+
|
|
34
|
+
先加载 subagent 服务、一个进程内或远程后端与本工具,然后指定提供方名称。此组合暴露一个委派给 `spawn` 后端的 `subagent` 工具:
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
- name: '@deepseek-ai/dsh-subagent'
|
|
38
|
+
- name: '@deepseek-ai/dsh-subagent-spawn-in-process'
|
|
39
|
+
- name: '@deepseek-ai/dsh-tool-subagent'
|
|
40
|
+
config:
|
|
41
|
+
provider: spawn
|
|
42
|
+
toolName: subagent
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| 字段 | 默认值 | 含义 |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `provider` | 必填 | `ctx.subagents` 上的提供方名称(如 `spawn`、`fork`、`acp`) |
|
|
48
|
+
| `toolName` | `subagent` | 面向模型的工具名称;每个已加载实例必须不同 |
|
|
49
|
+
| `modelSelectionSettings` | `false` | 为每个顶层 Session 读取宿主的精确路由授权偏好;常驻 preset 观察匹配 Session,直接 Agent setup 则显式传入其 Session;要求提供方支持 `agentOptions` |
|
|
50
|
+
| `agentOptions` | — | 配置的子级 `provider`、`model`、适配器所有的 `reasoningEffort` 与正整数 `maxTokens` 默认值;要求提供方支持 `agentOptions`,并会覆盖提供方持有的路由默认值 |
|
|
51
|
+
| `persona` | — | 每个子 agent 独立的 persona;要求提供方具备 `persona` 能力 |
|
|
52
|
+
| `toolFilter` | — | 每个子 agent 独立的全局工具限制;要求提供方具备 `toolFilter` 能力 |
|
|
53
|
+
| `maxDepth` | Host 设置(`1`) | 绝对委派深度上限(`0` 禁止委派);`'provider-managed'` 不向进程外提供方发送上限 |
|
|
54
|
+
|
|
55
|
+
生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-tool-subagent)是每个受支持字段及其 JSDoc 的穷尽式真源。
|
|
56
|
+
|
|
57
|
+
### 受管理的委派
|
|
58
|
+
|
|
59
|
+
运行时接受子任务后,每次调用都会返回 `started subagent <childId>`,不等待子任务结果。activation 独立于已完成的工具调用拥有这项工作;运行时发送完成通知并释放执行资源。
|
|
60
|
+
|
|
61
|
+
所有后端的完成通知都会附带最终回答。本地 Spawn 和 Fork 子任务还可以发送消息,在活跃期间通过 `send_message` 接受更多工作,或在结束后恢复。Codex、Claude Code、ACP 与 DSH SDK 后端不接受后续消息。
|
|
62
|
+
|
|
63
|
+
`maxDepth` 限制递归深度(`0` 禁止委派);省略时,每次委派读取 Host 当前的 `subagent.maxDepth` 设置,初始值为 `1`。数值深度要求提供方具备 `depthLimit` 能力;`'provider-managed'` 把预算留给进程外提供方。当提供方支持时,`persona` 与 `toolFilter` 会配置每个子 agent;工具在达到上限时仍然可见——每次尝试启动都会检查调用 agent 的当前深度,被拒绝时返回出错的工具结果。
|
|
64
|
+
|
|
65
|
+
### 选择子级 LLM
|
|
66
|
+
|
|
67
|
+
设置 `modelSelectionSettings: true`,即可在组合每个全新顶层 Session 时读取宿主的 `subagent-model-selection` 偏好。没有已记录策略的恢复 Session 会保持禁用,包括显式为空的恢复。启用后,非空的精确 provider/model 路由列表会记录进 Session、由子 Session 继承,后续设置编辑不会改变它。工具随后公开可选的 `provider`、`model` 与 `reasoning_effort` 字段,并注册共享的 `list_subagent_models` 工具。此模式要求后端声明 `agentOptions`;两个进程内后端和 DSH SDK 支持该能力,而 ACP、Codex 与 Claude Code 会拒绝它,而不是忽略它。
|
|
68
|
+
|
|
69
|
+
一次调用需同时提供 `provider` 与 `model`;当配置值、父 agent 值或提供方持有的默认值能提供路由时,也可只提供推理等级。静态的 `provider.agentRouteDefaults` 在存在时构成提供方/模型基线;工具配置与模型字段会在路由相关强度合并和确切路由预检前覆盖它。没有这些默认值的提供方会使用父 agent 最新已记录请求中的兼容值,再使用父级首次请求前的创建选项,并保留配置的 `maxTokens`。更改路由但未显式提供推理等级时,会清除继承的路由自有等级,使所选模型解析自己的默认值。实时 LLM 适配器在创建子 agent 前校验有效路由。目录成员资格只提供建议,因此适配器接受时,模型可以使用未列出的 id。
|
|
70
|
+
|
|
71
|
+
-----
|
|
72
|
+
|
|
73
|
+
<a id="understand-the-implementation"></a>
|
|
74
|
+
## 理解实现
|
|
75
|
+
|
|
76
|
+
<details>
|
|
77
|
+
<summary>实现细节——点击展开</summary>
|
|
78
|
+
|
|
79
|
+
本节解释工具如何镜像提供方生命周期并结算运行;可观察行为已在[使用本包](#use-this-package)中说明。
|
|
80
|
+
|
|
81
|
+
### 设计理念
|
|
82
|
+
|
|
83
|
+
一个实例就是一个提供方加一个工具名称。插件镜像提供方生命周期:具名提供方出现时注册工具,提供方离开时释放工具,因此同级加载顺序与 HMR 替换不会让工具悬空。直接 Agent setup 显式传入尚未发布的 Session,并在发布前等待安装完成。由设置控制的常驻 preset 通过 `agent/created` 接收每个匹配 Agent,从其 Session 选择策略,并等待通过其 Context 发起的安装;安装失败会拒绝创建。提供方无法执行的数值型 `maxDepth` 或已配置 LLM 选择会在挂载时失败,而不是在首次委派时失败。每个工具作用域内最多一个实例可以拥有模型选择,因为 `list_subagent_models` 使用全局名称。
|
|
84
|
+
|
|
85
|
+
### Activation 所有权
|
|
86
|
+
|
|
87
|
+
工具调用 `ctx.subagents.startActivation()`,并选择向父任务交付。运行时拥有启动取消、执行、结果汇报与清理。启动失败产生出错的工具结果;发布后的失败通过完成通知到达,运行时保留诊断和部分输出。
|
|
88
|
+
|
|
89
|
+
### 结果确认
|
|
90
|
+
|
|
91
|
+
规范工具结果为 `{ kind: 'activation', subagentId }`。其中没有执行 Promise 或最终输出;需要等待结果的程序调用方直接使用 subagent 服务。
|
|
92
|
+
|
|
93
|
+
### 随上下文变化的措辞
|
|
94
|
+
|
|
95
|
+
工具描述源自 `provider.inheritsParentContext`:全新子 agent 得到「it does not see this conversation」措辞,fork 子 agent 得到「it does not see the current in-flight turn」措辞,因此模型既不会复述、也不会省略并不存在的上下文。
|
|
96
|
+
|
|
97
|
+
### 源码地图
|
|
98
|
+
|
|
99
|
+
| 文件 | 职责 |
|
|
100
|
+
|---|---|
|
|
101
|
+
| [`src/index.ts`](src/index.ts) | 工具注册、提供方生命周期镜像、activation 请求 |
|
|
102
|
+
| [`src/model-selection.ts`](src/model-selection.ts) | 请求/配置合并与实时 LLM 路由预检 |
|
|
103
|
+
| [`src/model-selection-settings.ts`](src/model-selection-settings.ts) | 为新 Session 读取的宿主所有 opt-in 设置 |
|
|
104
|
+
| [`src/model-selection-state.ts`](src/model-selection-state.ts) | 记录并继承已读取决定的 Session 事件 |
|
|
105
|
+
| [`src/list-models.ts`](src/list-models.ts) | `list_subagent_models` 运行时发现工具 |
|
|
106
|
+
|
|
107
|
+
</details>
|
|
108
|
+
|
|
109
|
+
-----
|
|
110
|
+
|
|
111
|
+
<a id="further-exploration"></a>
|
|
112
|
+
## 进一步探索
|
|
113
|
+
|
|
114
|
+
当包级约定不够用时阅读以下页面;它们从工具运行时行为进入它所委派其上的 seam,以及相邻的子 agent 工具。
|
|
115
|
+
|
|
116
|
+
- [Subagent 子系统](../../../docs/subsystems/subagent.zh.md)——提供方、activation、结果与继续执行。
|
|
117
|
+
- [dsh-tool-subagent-control](../tool-subagent-control/README.zh.md)——可继续子 agent 的消息、中断与列表工具。
|
|
118
|
+
- [生成工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-subagent)——默认 schema 与后端相关的措辞。
|
|
119
|
+
- [生成配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-tool-subagent)——每个受支持配置字段。
|
|
120
|
+
- [历史模型选择 subagent 路由](../../../.agents/notes/archived/feature/2026-08-18-model-selected-subagent-routes.md)——选择策略、继承、发现与 fork 限制。
|
|
121
|
+
|
|
122
|
+
-----
|
|
123
|
+
|
|
124
|
+
<a id="model-experience"></a>
|
|
125
|
+
## 模型体验
|
|
126
|
+
|
|
127
|
+
### 工具 schema
|
|
128
|
+
|
|
129
|
+
#### 模型看到什么
|
|
130
|
+
|
|
131
|
+
提供方存在时,以配置的工具名称公开生成的默认 [`subagent` schema](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-subagent)。启用的 Session 策略会添加 `provider`、`model`、`reasoning_effort` 和路由指引;后端必须支持 `agentOptions`。上下文继承和继续执行能力决定任务与后续消息的描述。工具限制会同时移除 schema 及其 `tool:<toolName>` 指引 section。
|
|
132
|
+
|
|
133
|
+
#### Token 影响
|
|
134
|
+
|
|
135
|
+
每个父级请求支付固定的 schema 成本;模型选择增加三个参数。每个工具实例增加一个 schema 和一个简短的系统提示词 section。
|
|
136
|
+
|
|
137
|
+
#### KV Cache 影响
|
|
138
|
+
|
|
139
|
+
只要提供方实例及其配置不变,前缀就保持稳定。适配器目录变化不会改变定义;子级路由覆盖可能使 fork 子 agent 无法复用继承的父级前缀。
|
|
140
|
+
|
|
141
|
+
### 模型选择与发现
|
|
142
|
+
|
|
143
|
+
#### 模型看到什么
|
|
144
|
+
|
|
145
|
+
Session 携带策略的 settings 控制实例会公开子级 LLM 选择字段与 `list_subagent_models`。可选 `ctx.llm` 服务不可用时,调用会失败。发现只返回精确路由策略中的已注册提供方与已公布模型;未授权提供方会在调用其适配器目录前被拒绝,精确查询也必须先获准,才会解析模型的推理强度与默认值。执行阶段会独立强制同一策略。
|
|
146
|
+
|
|
147
|
+
#### Token 影响
|
|
148
|
+
|
|
149
|
+
启用的组合中存在一个固定发现 schema。只有模型调用工具时,目录内容才进入 transcript。
|
|
150
|
+
|
|
151
|
+
#### KV Cache 影响
|
|
152
|
+
|
|
153
|
+
适配器注册与目录变化不会改变 schema 前缀。每个发现结果都追加在可复用前缀之后。
|
|
154
|
+
|
|
155
|
+
### 系统提示词
|
|
156
|
+
|
|
157
|
+
#### 模型看到什么
|
|
158
|
+
|
|
159
|
+
可见的委派工具共享一段指导,列出按名称排序的工具,指示模型一起启动相互独立的委派,并在它们运行时继续工作。隐藏或不可用的工具不列入其中;没有可见工具时,不输出指导。`subagent` 和 `subagent_fork` 都可见时,文本为:
|
|
160
|
+
|
|
161
|
+
##### 工具指导 section
|
|
162
|
+
|
|
163
|
+
```markdown
|
|
164
|
+
Start independent delegations with `subagent` or `subagent_fork` together in one assistant message and continue useful work while they run.
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### Token 影响
|
|
168
|
+
|
|
169
|
+
每个父级请求最多包含一段简短的委派指导,列出该请求可见的工具名。
|
|
170
|
+
|
|
171
|
+
#### KV Cache 影响
|
|
172
|
+
|
|
173
|
+
可见工具名不变时,前缀保持稳定;增加或移除可见工具会更改这段指导。
|
|
174
|
+
|
|
175
|
+
### 启动结果
|
|
176
|
+
|
|
177
|
+
#### 模型看到什么
|
|
178
|
+
|
|
179
|
+
调用保留任务描述与提示词。成功返回 `started subagent <childId>`;启动被拒绝则返回错误。子任务执行详情独立于这条确认交付。
|
|
180
|
+
|
|
181
|
+
#### Token 影响
|
|
182
|
+
|
|
183
|
+
提示词与确认保留在父级历史中,直到上下文压缩;子任务工作上下文留在子任务中。
|
|
184
|
+
|
|
185
|
+
#### KV Cache 影响
|
|
186
|
+
|
|
187
|
+
仅追加;新增可见内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
|
|
188
|
+
|
|
189
|
+
### 完成交付
|
|
190
|
+
|
|
191
|
+
#### 模型看到什么
|
|
192
|
+
|
|
193
|
+
回答投递遵循上文的受管理委派规则。返回的子任务 id 用于后续控制与目录操作;只有支持继续执行的后端才接受后续消息。
|
|
194
|
+
|
|
195
|
+
#### Token 影响
|
|
196
|
+
|
|
197
|
+
消息与完成通知独立于启动确认追加到父级历史。工具结果本身不包含最终输出。
|
|
198
|
+
|
|
199
|
+
#### KV Cache 影响
|
|
200
|
+
|
|
201
|
+
仅追加;新增可见内容位于可复用请求前缀之后,不会使现有 KV Cache 条目失效。
|
|
202
|
+
|
|
203
|
+
## 已知限制与延期工作
|
|
204
|
+
|
|
205
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
这些限制说明本工具不返回或不强制执行什么;它们是当前包约束。
|
|
209
|
+
|
|
210
|
+
- **本工具不等待结果**——使用完成通知或子任务消息。程序化结果等待由 subagent 服务提供。
|
|
211
|
+
- **随附 fork 工具不能选择子级 LLM 路由**——它们继承父级提供方与模型,使复制的对话前缀仍有资格复用 KV Cache。仅当路由变更能保留复用或公开有界重算成本时,才重新启用选择。
|
|
212
|
+
- **非路由子 agent 策略按实例固定**——另一个 persona、工具过滤器或深度上限需要另一个名称不同的工具。LLM 选择要求启用逐 Session 偏好,且提供方必须声明 `agentOptions`;两个进程内提供方和 DSH SDK 会声明该能力,而 ACP、Codex 与 Claude Code 会拒绝它,而不是忽略它。
|
|
213
|
+
|
|
214
|
+
<a id="dev-note"></a>
|
|
215
|
+
### 开发备注
|
|
216
|
+
|
|
217
|
+
<details>
|
|
218
|
+
<summary>维护者的工作上下文——点击展开</summary>
|
|
219
|
+
|
|
220
|
+
无。
|
|
221
|
+
|
|
222
|
+
</details>
|