@deepseek-ai/dsh-tool-subagent 0.2.2-rc.1 → 0.2.2-rc.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-selection-state.js","sourceRoot":"","sources":["../../src/model-selection-state.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,OAAO,EAAE,CAAC,IAAI,GAAG,EAAE,MAAM,KAAK,CAAA;AAI9B,OAAO,EAAE,wBAAwB,EAA0B,MAAM,sBAAsB,CAAA;AAiBvF,MAAM,0BAA0B,GAA4C,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;IAC/F,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC3B,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;AAE9B;;;GAGG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAAG;IACxD,GAAG,EAAE,8BAA8B;IACnC,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,0BAA0B;IACvC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;IAChB,KAAK,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACvB,IAAI,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,iCAAiC;YAAE,OAAO,MAAM,CAAA;QACtF,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC,IAAI,CAAA;QACpC,wBAAwB,CAAC,aAAa,CAAC,CAAA;QACvC,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;QAChF,CAAC;QACD,OAAO,aAAa,CAAA;IACtB,CAAC;CACyF,CAAA;AAE5F;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,sCAAqG,EACrG,OAAgB;IAEhB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAA;AAC9F,CAAC"}
@@ -41,26 +41,24 @@ export interface DelegationModelRequest {
41
41
  */
42
42
  export declare function hasDelegationModelRequest(request: DelegationModelRequest): boolean;
43
43
  /**
44
- * Merge model-supplied selection fields over configured child defaults.
45
- * Provider and model form one route and must be supplied together. Changing
46
- * that route without an effort clears the configured route-owned effort.
47
- * @param parentOptions - Current parent values that supply missing child values.
44
+ * Validate explicit selection against the Session policy and merge it over child defaults.
45
+ * Explicit selection requires both provider and model; an omitted effort then
46
+ * uses the selected model's default, even when the route is unchanged.
48
47
  * @param configured - Tool-instance child defaults.
49
48
  * @param request - Model-facing route override.
50
49
  * @param enabled - Whether this tool instance permits model-facing selection.
50
+ * @param policy - Session allowlist; omission permits only the current parent route.
51
+ * @param parentOptions - Current parent route used when no policy is recorded.
51
52
  * @returns Child Agent options, preserving omission when no layer contributes one.
52
53
  */
53
- export declare function requestedAgentOptions(parentOptions: AgentOptions, configured: AgentOptions | undefined, request: DelegationModelRequest, enabled: boolean): AgentOptions | undefined;
54
+ export declare function requestedAgentOptions(configured: AgentOptions | undefined, request: DelegationModelRequest, enabled: boolean, policy: ModelSelectionPolicy | undefined, parentOptions: AgentOptions): AgentOptions | undefined;
54
55
  /**
55
- * Enforce a settings-owned route list at the operation that creates the child.
56
- * Pure inheritance remains outside this policy because no model-facing choice
57
- * occurred; any explicit route or effort field must resolve to an allowed route.
56
+ * Enforce Session authorization for a complete, explicitly selected child route.
58
57
  * @param policy - Session allowlist; omission permits only the current parent route.
59
- * @param parentOptions - Current parent values that supply missing child values.
60
- * @param requested - Effective child options after request/config merging.
61
- * @param request - Model-facing selection fields from the tool call.
58
+ * @param parentOptions - Current parent route used when no policy is recorded.
59
+ * @param route - Validated provider/model pair from the tool call.
62
60
  */
63
- export declare function assertAllowedModelSelection(policy: ModelSelectionPolicy | undefined, parentOptions: AgentOptions, requested: AgentOptions | undefined, request: DelegationModelRequest): void;
61
+ export declare function assertAllowedModelSelection(policy: ModelSelectionPolicy | undefined, parentOptions: AgentOptions, route: AllowedModelRoute): void;
64
62
  /**
65
63
  * Whether configured Agent options require route validation before delegation.
66
64
  * @param options - Tool-instance child defaults.
@@ -75,7 +73,7 @@ export declare function hasConfiguredLlmSelection(options: AgentOptions | undefi
75
73
  * @param parentOptions - Current parent values whose compatible fields the child inherits.
76
74
  * @param requested - Per-child options after request/config merging.
77
75
  * @param signal - Tool-call cancellation signal.
78
- * @param inheritParentReasoningEffort - Whether an omitted effort may inherit from the parent route.
76
+ * @param inheritParentReasoningEffort - Whether an omitted effort may inherit from the parent route; false for explicit model selection.
79
77
  */
80
78
  export declare function preflightChildLlmRoute(llm: LlmRuntime, parentOptions: AgentOptions, requested: AgentOptions | undefined, signal: AbortSignal, inheritParentReasoningEffort?: boolean): Promise<void>;
81
79
  //# sourceMappingURL=model-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-selection.d.ts","sourceRoot":"","sources":["../../src/model-selection.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAGvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,iEAAiE;AACjE,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,i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;QACR,KAAK;QACL,GAAG,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE;KAC5D,EAAE,MAAM,CAAC,CAAA;AACZ,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-selection.d.ts","sourceRoot":"","sources":["../../src/preset-selection.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAEjE,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,kGAAkG;IAClG,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iGAAiG;IACjG,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;CAC3C;AAED,uDAAuD;AACvD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,mFAAmF;AACnF,qBAAa,uBAAuB;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,qBAAqB;IAW1D,6FAA6F;IAC7F,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,oDAAoD;IACpD,IAAI,OAAO,IAAI,SAAS,MAAM,EAAE,GAAG,SAAS,CAE3C;IAED,oDAAoD;IACpD,IAAI,WAAW,IAAI,MAAM,CAKxB;IAED;;;OAGG;IACH,cAAc,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAMhD;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,GAAG,SAAS;CAS7D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-selection.js","sourceRoot":"","sources":["../../src/preset-selection.ts"],"names":[],"mappings":"AAgBA,mFAAmF;AACnF,MAAM,OAAO,uBAAuB;IACL;IAA7B,YAA6B,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;QACxD,MAAM,EAAE,WAAW,EAAE,mB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YAAY,CAAA;QAC/B,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAA;QACpD,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;QAC5G,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC5E,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC;CACF"}
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.2-rc.1",
4
+ "version": "0.2.2-rc.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -32,18 +32,21 @@
32
32
  "locale/model-selection-settings/*.json",
33
33
  "lib/index.js",
34
34
  "lib/model-selection-settings.js",
35
- "lib/types/**/*.d.ts"
35
+ "lib/types/**/*.d.ts",
36
+ "lib/types/**/*.d.ts.map",
37
+ "lib/**/*.js.map",
38
+ "src"
36
39
  ],
37
40
  "license": "MIT",
38
41
  "peerDependencies": {
39
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
40
- "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.1",
41
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
42
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
43
- "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
44
- "@deepseek-ai/dsh-subagent": "0.2.2-rc.1",
45
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
46
- "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
42
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
43
+ "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.3",
44
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
45
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
46
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.3",
47
+ "@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
48
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
49
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.3",
47
50
  "@deepseek-ai/cordis": "~4.1.0"
48
51
  },
49
52
  "peerDependenciesMeta": {
@@ -53,23 +56,23 @@
53
56
  },
54
57
  "dependencies": {
55
58
  "@deepseek-ai/schemastery": "~3.19.0",
56
- "zod": "4.4.3"
59
+ "zod": "4.6.6"
57
60
  },
58
61
  "devDependencies": {
59
62
  "@deepseek-ai/cordis-plugin-loader": "~1.1.0",
60
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
61
- "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.1",
62
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
63
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
64
- "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.1",
65
- "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.1",
66
- "@deepseek-ai/dsh-subagent": "0.2.2-rc.1",
67
- "@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.2-rc.1",
68
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
69
- "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.1",
70
- "@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.1",
71
- "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
63
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
64
+ "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.3",
65
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
66
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
67
+ "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.3",
68
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.3",
69
+ "@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
70
+ "@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.2-rc.3",
71
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
72
+ "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.3",
73
+ "@deepseek-ai/dsh-tool-testkit": "0.2.2-rc.3",
74
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.3",
72
75
  "@deepseek-ai/cordis": "~4.1.0",
73
- "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1"
76
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.3"
74
77
  }
75
78
  }
package/src/index.ts ADDED
@@ -0,0 +1,393 @@
1
+ /**
2
+ * Model-facing delegation through one configured `ctx.subagents` provider.
3
+ * Provider lifecycle controls tool registration and context-sensitive schema
4
+ * wording. Every delegation starts a managed activation and returns its child
5
+ * id; the subagent runtime owns result delivery and resource cleanup.
6
+ * @module @deepseek-ai/dsh-tool-subagent
7
+ */
8
+
9
+ import type { Context } from '@deepseek-ai/cordis'
10
+ import z from '@deepseek-ai/schemastery'
11
+ import type {} from '@deepseek-ai/dsh-agent-preset-registry'
12
+ import { defineTool } from '@deepseek-ai/dsh-tools'
13
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools'
14
+ import type { AgentOptions } from '@deepseek-ai/dsh-agent'
15
+ import { ReasoningEffortId } from '@deepseek-ai/dsh-llm'
16
+ import type { ContentBlock } from '@deepseek-ai/dsh-llm'
17
+ import {
18
+ assertSubagentMaxDepth,
19
+ delegationDepthOf,
20
+ parentAgentOptionsForDelegation,
21
+ } from '@deepseek-ai/dsh-subagent'
22
+ import type { SubagentProvider } from '@deepseek-ai/dsh-subagent'
23
+ import {
24
+ hasConfiguredLlmSelection,
25
+ hasDelegationModelRequest,
26
+ preflightChildLlmRoute,
27
+ requestedAgentOptions,
28
+ } from './model-selection.ts'
29
+ import type { DelegationModelRequest } from './model-selection.ts'
30
+ import { registerListSubagentModels } from './list-models.ts'
31
+ import { SubagentPresetSelection, type PresetSelectionConfig, type PresetSelectionRequest } from './preset-selection.ts'
32
+ import {
33
+ subagentModelSelectionProjectionDefinition,
34
+ subagentModelSelectionPolicy,
35
+ } from './model-selection-state.ts'
36
+
37
+ export const name = 'tool-subagent'
38
+ export const inject = ['tools', 'subagents', 'systemPrompt', 'sessionProjections']
39
+
40
+ // Definition identity keeps shared guidance scoped to the actual visible tools,
41
+ // including scoped overrides and independently loaded tool registries.
42
+ const delegationTools = new Set<ToolDefinition>()
43
+
44
+ /** Config: which registered provider this tool delegates to, plus child defaults. */
45
+ export interface Config extends PresetSelectionConfig {
46
+ /** The `ctx.subagents` provider name to start runs on (e.g. `spawn`, `acp`). */
47
+ provider: string
48
+ /**
49
+ * Model-facing tool name (default `subagent`). Each loaded instance must use
50
+ * a distinct name.
51
+ */
52
+ toolName?: string
53
+ /**
54
+ * Expose optional child `provider`, `model`, and `reasoning_effort` fields.
55
+ * Requires provider `agentOptions` support. Execution enforces the Session
56
+ * policy, or restricts explicit selection to the current parent route.
57
+ */
58
+ modelSelection?: boolean
59
+ /**
60
+ * Register the shared `list_subagent_models` tool for this scope.
61
+ * Enable on only one instance per scope; defaults to false and does not
62
+ * enable model selection. Discovery is removed when this instance unloads.
63
+ */
64
+ modelDiscovery?: boolean
65
+ /**
66
+ * Agent options applied to every child; omitted fields use child-loop defaults.
67
+ */
68
+ agentOptions?: AgentOptions
69
+ /**
70
+ * Maximum child depth: a non-negative safe integer (`0` forbids delegation),
71
+ * or `'provider-managed'` to send no cap. A numeric cap
72
+ * requires the provider's `depthLimit` capability (mount fails loud
73
+ * otherwise). The provider checks the calling agent's current depth at every
74
+ * start; the tool remains model-visible so runtime policy owns rejection.
75
+ * `'provider-managed'` is for an out-of-process provider whose recursion
76
+ * budget belongs to the child runtime or its own deployment. Omission reads
77
+ * the current Host subagent depth setting (default `1`) at each delegation.
78
+ */
79
+ maxDepth?: number | 'provider-managed'
80
+ }
81
+
82
+ export const Config: z<Config> = z.object({
83
+ provider: z.string().required(),
84
+ toolName: z.string().default('subagent'),
85
+ modelSelection: z.boolean().default(false),
86
+ modelDiscovery: z.boolean().default(false),
87
+ // Prevent Schemastery from materializing omitted agentOptions as `{}`.
88
+ agentOptions: z.object({
89
+ provider: z.string(),
90
+ model: z.string(),
91
+ reasoningEffort: z.string().min(1) as z<ReturnType<typeof ReasoningEffortId> | undefined>,
92
+ maxTokens: z.number().step(1).min(1).max(Number.MAX_SAFE_INTEGER),
93
+ }).default(undefined as unknown as {
94
+ provider: string
95
+ model: string
96
+ reasoningEffort: ReturnType<typeof ReasoningEffortId>
97
+ maxTokens: number
98
+ }),
99
+ agentPreset: z.string().min(1),
100
+ allowedAgentPresets: (z.array(z.string().min(1)).min(1) as z<string[] | undefined>).default(undefined),
101
+ maxDepth: z.union([z.natural().max(Number.MAX_SAFE_INTEGER), z.const('provider-managed' as const)]),
102
+ })
103
+
104
+ /**
105
+ * Model-facing wording from the provider's conversation-history descriptor
106
+ * ({@link SubagentProvider.inheritsParentContext}).
107
+ * A fresh child needs a standalone prompt; a forked child already sees the
108
+ * conversation's completed turns — telling the model to restate everything
109
+ * (or, worse, that the child "does not see this conversation") would be false
110
+ * for a fork.
111
+ * @param inheritsConversation - whether the child's conversation is seeded
112
+ * with the parent's completed turns; this says nothing about tool, service,
113
+ * scope, or authority inheritance.
114
+ * @returns the tool `description` and the `prompt` parameter description.
115
+ */
116
+ function providerWording(inheritsConversation: boolean): { description: string; promptDescription: string } {
117
+ if (inheritsConversation) {
118
+ return {
119
+ description:
120
+ 'Delegate a task to a subagent that inherits this conversation: a child agent seeded with all '
121
+ + 'completed turns so far (it does not see the current in-flight turn). Use this when the subtask '
122
+ + 'builds on this conversation\'s context — a follow-up analysis, '
123
+ + 'a review, a continuation — without consuming this conversation\'s context for the work itself. '
124
+ + 'You receive its result, not its intermediate steps.',
125
+ promptDescription:
126
+ 'The task for the subagent. It already sees this conversation\'s completed turns, so build on them '
127
+ + 'freely and state only what is new.',
128
+ }
129
+ }
130
+ return {
131
+ description:
132
+ 'Delegate a self-contained task to a subagent (a separate agent that works in its own context) '
133
+ + 'to offload focused, independent work — research, a scoped '
134
+ + 'implementation, an analysis — so it does not consume this conversation\'s context. The subagent '
135
+ + 'returns its result, not its intermediate steps.',
136
+ promptDescription:
137
+ 'The complete, self-contained task for the subagent. It does not share this '
138
+ + 'conversation\'s context, so include everything it needs.',
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Install one delegation-tool composition.
144
+ * The owning composition shares its registrations across Agents; child startup resolves the selected preset.
145
+ * @param ctx - Context that owns the registrations.
146
+ * @param config - delegation-tool configuration.
147
+ * @returns when the plugin is ready.
148
+ */
149
+ export async function apply(ctx: Context, config: Config): Promise<void> {
150
+ for (const field of ['persona', 'toolFilter']) {
151
+ if (Object.hasOwn(config, field)) {
152
+ throw new Error(`tool-subagent: ${field} is no longer supported; configure persona and tool plugins in an Agent Preset and select it with agentPreset (spawn only)`)
153
+ }
154
+ }
155
+ const presets = new SubagentPresetSelection(config)
156
+ if (presets.configured && ctx.get('agentPresets') === undefined) {
157
+ throw new Error('tool-subagent: agent preset selection requires the agent-presets service')
158
+ }
159
+ // Direct apply() bypasses Schemastery's numeric constraints. A direct-apply
160
+ // omission stays capless (the schema default only runs through the loader).
161
+ if (config.maxDepth !== 'provider-managed') assertSubagentMaxDepth(config.maxDepth)
162
+ const toolName = config.toolName ?? 'subagent'
163
+
164
+ const modelSelectionEnabled = config.modelSelection === true
165
+ const subagentModelSelectionProjectionHandle = await ctx.sessionProjections.register(subagentModelSelectionProjectionDefinition)
166
+
167
+ const assertSubagentProviderConfiguration = (subagentProvider: SubagentProvider): void => {
168
+ presets.assertProvider(subagentProvider)
169
+ if (ctx.subagents.resolveMaxDepth(config.maxDepth) !== undefined && !subagentProvider.capabilities.depthLimit) {
170
+ throw new Error(
171
+ `tool-subagent: provider "${subagentProvider.name}" cannot enforce maxDepth (no depthLimit capability) — `
172
+ + 'set maxDepth: \'provider-managed\' to leave the recursion budget to the provider',
173
+ )
174
+ }
175
+ if (config.agentOptions !== undefined && !subagentProvider.capabilities.agentOptions) {
176
+ throw new Error(
177
+ `tool-subagent: provider "${subagentProvider.name}" does not support child agentOptions`,
178
+ )
179
+ }
180
+ if (modelSelectionEnabled && !subagentProvider.capabilities.agentOptions) {
181
+ throw new Error(
182
+ `tool-subagent: provider "${subagentProvider.name}" does not support child model selection`,
183
+ )
184
+ }
185
+ }
186
+
187
+ // Validate provider-owned config outside the optional LLM binding so an
188
+ // invalid provider always rejects its registration or this plugin's load.
189
+ ctx.on('subagent/provider-added', (subagentProvider) => {
190
+ if (subagentProvider.name === config.provider) assertSubagentProviderConfiguration(subagentProvider)
191
+ })
192
+ const initialProvider = ctx.subagents.getProvider(config.provider)
193
+ if (initialProvider !== undefined) assertSubagentProviderConfiguration(initialProvider)
194
+
195
+ if (config.modelDiscovery === true) registerListSubagentModels(ctx, subagentModelSelectionProjectionHandle)
196
+
197
+ // Load order and HMR replacement can change provider availability while
198
+ // this fiber remains active.
199
+ let mounted: { subagentProvider: SubagentProvider; definition: ToolDefinition; disposeTool: () => void } | undefined
200
+ const mount = (subagentProvider: SubagentProvider): void => {
201
+ assertSubagentProviderConfiguration(subagentProvider)
202
+ const wording = providerWording(subagentProvider.inheritsParentContext)
203
+ const providerRouteDefaults = subagentProvider.agentRouteDefaults
204
+ const selectionDescription = providerRouteDefaults !== undefined
205
+ ? ' Omit `provider`, `model`, and `reasoning_effort` to use child defaults, falling back to this backend\'s route defaults.'
206
+ : ' Omit `provider`, `model`, and `reasoning_effort` to use child defaults, falling back to compatible parent values.'
207
+ const definition = defineTool({
208
+ name: toolName,
209
+ description: wording.description
210
+ + ' This tool starts an independently managed subagent and immediately returns its name. If you are still online when it finishes, the runtime automatically delivers its completion notice. The notice includes the final answer unless the child sent you a message just before finishing.'
211
+ + (subagentProvider.prepareContinuable !== undefined
212
+ ? ' Use `send_message` to steer it while running or continue its conversation after it finishes.'
213
+ : ' This backend does not accept follow-up messages.')
214
+ + (modelSelectionEnabled ? selectionDescription : '')
215
+ + (modelSelectionEnabled && subagentProvider.inheritsParentContext
216
+ ? ' Changing the route can prevent provider-side reuse of the inherited conversation prefix.'
217
+ : ''),
218
+ parameters: {
219
+ cwd: {
220
+ type: 'string',
221
+ description: 'Initial child working directory. Relative paths use your current directory; omitted inherits it. Later directory changes in either agent are independent.',
222
+ },
223
+ description: {
224
+ type: 'string',
225
+ required: true,
226
+ description: 'A short (3-5 word) description of the delegated task, for display. '
227
+ + "Use the language of the user's current request.",
228
+ },
229
+ name: {
230
+ type: 'string',
231
+ description: 'Optional short name for the subagent, unique among the subagents you create: lower-case letters, '
232
+ + 'digits, and hyphens, starting with a letter, at most 32 characters; lead is reserved for the root agent. Omitted names default to agent-1, agent-2, and so on.',
233
+ },
234
+ prompt: {
235
+ type: 'string',
236
+ required: true,
237
+ description: wording.promptDescription,
238
+ },
239
+ ...presets.choices === undefined ? {} : {
240
+ agent_preset: {
241
+ type: 'string' as const,
242
+ enum: [...presets.choices],
243
+ description: presets.description,
244
+ },
245
+ },
246
+ ...modelSelectionEnabled ? {
247
+ provider: {
248
+ type: 'string' as const,
249
+ description: 'Child LLM provider id; requires `model`.',
250
+ },
251
+ model: {
252
+ type: 'string' as const,
253
+ description: 'Model id within that provider; requires `provider`.',
254
+ },
255
+ reasoning_effort: {
256
+ type: 'string' as const,
257
+ description: 'Reasoning effort id; requires `provider` and `model`. Omit to use the selected model\'s default, even when it matches the parent or configured route.',
258
+ },
259
+ } : {},
260
+ },
261
+ output: {
262
+ schema: {
263
+ type: 'object',
264
+ additionalProperties: false,
265
+ properties: {
266
+ kind: { type: 'string', required: true, const: 'activation' },
267
+ name: { type: 'string', required: true },
268
+ },
269
+ },
270
+ render: (_args, value) => [{ type: 'text', text: `started subagent ${value.name}` }],
271
+ presentationMeta: (_args, value) => ({ kind: value.kind, name: value.name }),
272
+ },
273
+ isConcurrencySafe: () => true,
274
+ async execute(args, exec) {
275
+ const parent = exec.agent
276
+ if (!parent) {
277
+ // Non-agent callers provide no parent for delegation ownership.
278
+ throw new Error('subagent tool requires a calling agent (exec.agent was undefined)')
279
+ }
280
+
281
+ const routes = subagentModelSelectionPolicy(subagentModelSelectionProjectionHandle, parent.session)
282
+ const modelSelectionPolicy = routes === undefined ? undefined : { routes }
283
+ const agentPreset = presets.resolve(args as PresetSelectionRequest)
284
+ const modelRequest = args as DelegationModelRequest
285
+ const parentOptions = parentAgentOptionsForDelegation(parent)
286
+ const requiresRoutePreflight = hasDelegationModelRequest(modelRequest)
287
+ || hasConfiguredLlmSelection(config.agentOptions)
288
+ const configuredChildAgentOptions = requiresRoutePreflight && providerRouteDefaults !== undefined
289
+ ? { ...providerRouteDefaults, ...config.agentOptions }
290
+ : config.agentOptions
291
+ const requestedChildAgentOptions = requestedAgentOptions(
292
+ configuredChildAgentOptions,
293
+ modelRequest,
294
+ modelSelectionEnabled,
295
+ modelSelectionPolicy,
296
+ parentOptions,
297
+ )
298
+ if (requiresRoutePreflight) {
299
+ const llm = ctx.get('llm')
300
+ if (llm === undefined) {
301
+ throw new Error('cannot resolve the selected child LLM route because the `llm` service is unavailable')
302
+ }
303
+ const inheritParentReasoningEffort = providerRouteDefaults === undefined && !hasDelegationModelRequest(modelRequest)
304
+ await preflightChildLlmRoute(
305
+ llm,
306
+ parentOptions,
307
+ requestedChildAgentOptions,
308
+ exec.signal,
309
+ inheritParentReasoningEffort,
310
+ )
311
+ if (ctx.subagents.getProvider(config.provider) !== subagentProvider) {
312
+ throw new Error(`subagent provider "${config.provider}" changed while resolving the child LLM route; retry the delegation`)
313
+ }
314
+ }
315
+ exec.signal.throwIfAborted()
316
+ const maxDepth = ctx.subagents.resolveMaxDepth(config.maxDepth)
317
+ const request = {
318
+ ...args.cwd === undefined ? {} : { cwd: args.cwd },
319
+ prompt: [{ type: 'text', text: args.prompt }] as ContentBlock[],
320
+ parent,
321
+ ...agentPreset === undefined ? {} : { agentPreset },
322
+ ...requestedChildAgentOptions !== undefined ? { agentOptions: requestedChildAgentOptions } : {},
323
+ ...maxDepth !== undefined ? { maxDepth } : {},
324
+ }
325
+
326
+ const started = await ctx.subagents.startActivation({
327
+ provider: config.provider,
328
+ label: args.description,
329
+ ...args.name === undefined ? {} : { name: args.name },
330
+ ...request,
331
+ signal: exec.signal,
332
+ delivery: 'parent',
333
+ })
334
+ return { kind: 'activation' as const, name: started.name }
335
+ },
336
+ })
337
+ const disposeTool = ctx.effect(() => {
338
+ const unregister = ctx.tools.register(definition)
339
+ delegationTools.add(definition)
340
+ return () => {
341
+ delegationTools.delete(definition)
342
+ unregister()
343
+ }
344
+ })
345
+ // oxlint-disable-next-line typescript/no-misused-promises -- Tool and guidance disposal are synchronous.
346
+ mounted = { subagentProvider, definition, disposeTool }
347
+ }
348
+
349
+ // Register listeners before checking presence so no synchronous change is missed.
350
+ ctx.on('subagent/provider-added', (subagentProvider) => {
351
+ if (subagentProvider.name === config.provider && mounted === undefined) mount(subagentProvider)
352
+ })
353
+ ctx.on('subagent/provider-removed', (name) => {
354
+ if (name !== config.provider || mounted === undefined) return
355
+ mounted.disposeTool()
356
+ mounted = undefined
357
+ })
358
+ const present = ctx.subagents.getProvider(config.provider)
359
+ if (present !== undefined) {
360
+ mount(present)
361
+ } else {
362
+ // A backend fiber may activate later; a misspelled provider remains visible in this log.
363
+ ctx.logger.info(`subagent provider "${config.provider}" not registered yet; the "${config.toolName ?? 'subagent'}" tool will register when it appears`)
364
+ }
365
+ ctx.systemPrompt.section({
366
+ name: `tool:${toolName}`,
367
+ order: ctx.systemPrompt.getSectionOrder('TOOL_SUBAGENT'),
368
+ text: (context) => {
369
+ if (mounted === undefined) return ''
370
+ const visible = [...delegationTools]
371
+ .filter(tool => ctx.tools.get(tool.name, context.scope) === tool)
372
+ .map(tool => tool.name)
373
+ .sort()
374
+ if (visible[0] !== toolName) return ''
375
+ const names = visible.map(name => `\`${name}\``).join(' or ')
376
+ return `Start independent delegations with ${names} together in one assistant message and continue useful work while they run. When only waiting for their results remains, end your turn instead of sleeping or polling; the next result starts a new turn. Collect the subagent results required to complete the task before giving the user a final answer.\n\nBash, formatters, code generators, and scripts can overwrite concurrent edits without conflict detection; coordinate their changes explicitly. The agent integrating the work must review the final diff and run relevant tests.`
377
+ },
378
+ })
379
+ ctx.systemPrompt.context({
380
+ name: `tool:${toolName}:depth`,
381
+ order: ctx.systemPrompt.getContextOrder('SUBAGENT_DELEGATION'),
382
+ text: (context) => {
383
+ if (context.agent === undefined || mounted === undefined
384
+ || ctx.tools.get(toolName, context.scope) !== mounted.definition) return ''
385
+ const maxDepth = ctx.subagents.resolveMaxDepth(config.maxDepth)
386
+ if (maxDepth === undefined) return ''
387
+ const depth = delegationDepthOf(context.agent)
388
+ if (depth < maxDepth) return ''
389
+ return `Delegation depth for \`${toolName}\`: current ${depth}, maximum ${maxDepth}, remaining levels 0.`
390
+ + ` Do not call \`${toolName}\` at this depth; carry out the work directly.`
391
+ },
392
+ })
393
+ }