Implement the continuable background subagents RFC: a durable child session with a series of Task-backed activations, each disposing its run before the Task settles. - dsh-subagent: rename SubagentRun.sendMessage to strict steer, drop run-level resume, add SubagentProvider.resume dispatch via SubagentService.resume, the continuation start field, and the versioned model-hidden subagent/descriptor session event. - dsh-subagent-inprocess/-spawn/-fork: publish the control-allocated child id, append the descriptor inside the initial turn, implement cold resume from the child's own transcript under the live parent scope, and strict running-only steer. - dsh-subagent-control (new): SubagentControlService owning stable child ids, descriptor snapshot/fold/authorization, Task-backed activation with settle-then-dispose ordering, the process-local active-run association, and steer-or-resume sendMessage routing. - dsh-tool-subagent: background route branches on the provider's resume capability (continuable via the control service; one-shot task for ACP), returning both child and task ids. - dsh-tool-subagent-control (new): the globally named send_message tool rendering steered/started routes. Keyless coverage spans Task ownership and disposal ordering, running delivery, cold follow-up, descriptor rejection and rollback, known-id reconstruction, kill during lookup, admission races, and a new subagent-continuable ACP snapshot scenario.
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
/**
|
|
* The in-process SPAWN subagent backend: registers a {@link SubagentProvider} on
|
|
* `ctx.subagents` that runs each child as a fresh child {@link Agent} on the same cordis
|
|
* context (its own session, own system prompt, zero parent context). The cheapest transport,
|
|
* reusing the agent factory's quiescent teardown.
|
|
* @module @deepseek-ai/dsh-subagent-spawn
|
|
*/
|
|
|
|
import type { Context } from 'cordis'
|
|
import z from 'schemastery'
|
|
import type { SubagentCapabilities, SubagentProvider, SubagentResumeRequest, SubagentStartRequest } from '@deepseek-ai/dsh-subagent'
|
|
import { resumeInProcessRun, startInProcessRun } from '@deepseek-ai/dsh-subagent-inprocess'
|
|
|
|
export const name = 'subagent-spawn'
|
|
// `tools` is deliberately not injected: the child factory already provides it during setup,
|
|
// and adding it here would unnecessarily change this provider's apply timing.
|
|
export const inject = ['subagents']
|
|
|
|
/** Config: the registry name to register the provider under. */
|
|
export interface Config {
|
|
/** Provider name on `ctx.subagents` (default `spawn`). */
|
|
providerName: string
|
|
}
|
|
|
|
export const Config: z<Config> = z.object({
|
|
providerName: z.string().default('spawn'),
|
|
})
|
|
|
|
/**
|
|
* The spawn provider. Supports every start-time capability: `depthLimit` (it
|
|
* constructs the child, so it can enforce a recursion cap), `outputSchema`
|
|
* (the scoped structured runtime), and `toolFilter`/`persona` (scoped
|
|
* `restrict()` and a scoped shadowing persona section, applied in the child's
|
|
* creation window).
|
|
*/
|
|
class SpawnProvider implements SubagentProvider {
|
|
readonly capabilities: SubagentCapabilities = { outputSchema: true, depthLimit: true, toolFilter: true, persona: true }
|
|
// Context contract: a spawned child starts fresh — it never sees the parent conversation.
|
|
readonly inheritsParentContext = false
|
|
|
|
constructor(readonly name: string) {}
|
|
|
|
start(request: SubagentStartRequest) {
|
|
// Fresh child: no seed. The shared driver mints ids, stamps cwd/lineage/
|
|
// depth, drives the one-shot (including the structured capture when the
|
|
// request carries an outputSchema), and maps the result.
|
|
return startInProcessRun(request, {})
|
|
}
|
|
|
|
resume(request: SubagentResumeRequest) {
|
|
// Cold resume reconstructs the persisted child from its own transcript
|
|
// under the live parent scope; the shared driver drives the follow-up turn.
|
|
return resumeInProcessRun(request)
|
|
}
|
|
}
|
|
|
|
export function apply(ctx: Context, config: Config): void {
|
|
ctx.subagents.registerProvider(new SpawnProvider(config.providerName))
|
|
}
|