/** * Adapter: spawns one isolated child agent per `agent()` call from a workflow. * * Wraps the existing `createDelegateChildHandle` so the workflow runtime stays * decoupled from the LLM stack (it sees only the `SubagentRunner` interface). * * Key behaviour: * - When `opts.schema` is provided, we inject `structured_output` into the child * tool set and unwrap the captured value on success. If the subagent finishes * without ever calling `structured_output`, we treat it as failure (`null`). * - Failures and aborts resolve to `null`. The workflow runtime continues — this * matches the pi-dynamic-workflows contract and keeps fan-out pipelines robust. * - We do NOT mutate `createDelegateChildHandle` — we just leverage its * `buildChildTools` injection point. */ import type { AgentTool } from '@earendil-works/pi-agent-core'; import type { Api, Model } from '@earendil-works/pi-ai'; import type { Config } from '../../config/schema.js'; import type { MessageBus } from '../../infra/bus/index.js'; import type { SessionStore } from '../../session/store.js'; import { type BuildChildToolsOptions } from '../child-agent-factory.js'; import type { ToolExecutorConfig } from '../tools/executor.js'; import type { SubagentRunOptions, SubagentRunner } from './types.js'; export interface DelegateSubagentRunnerDeps { workspace: string; bus: MessageBus; agentId?: string; /** Resolves the default subagent model (typically the parent agent's primary model). */ getDefaultModel: () => Model; getConfig: () => Config | undefined; toolExecutorConfig?: Partial; sessionStore?: SessionStore; /** * Provided by the workflow tool from `AgentToolsFactory` — mirrors how * `delegate-tool` is wired (avoids importing `tools/factory.ts` here and * breaking the existing factory ↔ delegate-tool ↔ child-agent-factory * dependency contract). */ buildChildTools: (opts: BuildChildToolsOptions) => AgentTool[]; } export declare class DelegateSubagentRunner implements SubagentRunner { private readonly deps; constructor(deps: DelegateSubagentRunnerDeps); run(prompt: string, opts: SubagentRunOptions): Promise; private preparePersistentSubagentSession; }