Replace the Task-backed continuation manager with one durable Session plus at
most one process-local Activation — a residency epoch for a reconstructed child
Agent, not a request, result, cancellation, or Task boundary. The manager owns
activation admission, authority, the live ownership graph, cold resume, and
child-first disposal; the Agent inbox is the only turn FIFO.
- startContinuable() is async and returns { childId, messageId } at inbox
acceptance; followup() takes a SubagentAuthority and returns AgentMessageId.
- SubagentProvider.resume?(), SubagentProviderResumeRequest, SubagentRun.steer?(),
SubagentProviderStartRequest and SubagentContinuation are deleted;
prepareContinuable?() is the continuable-creation capability.
- Cold resume calls ctx.agents.resume() from the manager through a private
activation-owner scope, never dispatching through a provider.
- Extract shared child composition, descriptor seeding, depth accounting, and
one-shot run settlement so the manager and one-shot driver keep one home
per fact.
Tests and docs follow in subsequent commits.
65 lines
2.5 KiB
TypeScript
65 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 {
|
|
ContinuableCreateSpec,
|
|
SubagentCapabilities,
|
|
SubagentProvider,
|
|
SubagentStartRequest,
|
|
} from '@deepseek-ai/dsh-subagent'
|
|
import { 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, {})
|
|
}
|
|
|
|
prepareContinuable(): Promise<ContinuableCreateSpec> {
|
|
// A spawned child starts fresh, so it contributes no seed; the continuation
|
|
// manager owns every later operation on it.
|
|
return Promise.resolve({})
|
|
}
|
|
}
|
|
|
|
export function apply(ctx: Context, config: Config): void {
|
|
ctx.subagents.registerProvider(new SpawnProvider(config.providerName))
|
|
}
|