import type { AgentMessage, 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 { EndpointToolRuntime } from '../endpoint-tools/index.js'; import type { MessageBus } from '../infra/bus/index.js'; import { type EmbeddedTranscriptRuntime } from './embedded/transcript-runtime.js'; import { createDelegationBudgetPolicy, type DelegationBudgetTier, type DelegationStopReason } from './orchestration/delegation-budget.js'; import type { RunVerification } from './coding/run-verification.js'; import type { ResearchCheckpointSink } from './orchestration/research-checkpoint.js'; import { type AgentAbortReason } from './orchestration/run-termination.js'; import type { ToolExecutorConfig } from './tools/executor.js'; export interface BuildChildToolsOptions { workspace: string; bus: MessageBus; model: Model; agentId?: string; getConfig: () => Config | undefined; toolExecutorConfig?: Partial; endpointTools?: EndpointToolRuntime; conversationId: string; } export interface DelegateChildProgressHooks { mode: 'steps' | 'full'; onProgress: (event: { type: 'tool_start' | 'tool_end' | 'iteration' | 'text_delta' | 'thinking_delta'; toolCallId?: string; toolName?: string; args?: Record; isError?: boolean; count?: number; max?: number; delta?: string; }) => void; } export interface DelegateChildHandleOptions { isWorkspaceTrusted?: (workspaceDir: string) => boolean | null | undefined; /** Host-owned completion signal, e.g. a validated structured result. */ isComplete?: () => boolean; authorizeToolCall?: import('./orchestration/agent-turn-policy.js').AgentTurnPolicyOptions['authorizeToolCall']; workspace: string; goal: string; context?: string; requesterConversationId?: string; allowedToolNames: string[]; maxIterations: number; budgetTier?: DelegationBudgetTier; model: Model; bus: MessageBus; agentId?: string; getConfig: () => Config | undefined; toolExecutorConfig?: Partial; /** * Construct the child agent's tool set. Injected by the caller (delegate-tool) * so this module does not import `tools/factory.js` (which would form a * factory ↔ delegate-tool ↔ child-agent-factory cycle). */ buildChildTools: (opts: BuildChildToolsOptions) => AgentTool[]; /** Optional live progress for delegated agents. */ progressHooks?: DelegateChildProgressHooks; transcriptRuntime?: EmbeddedTranscriptRuntime; conversationId?: string; timeoutMs?: number; verifyChanges?: boolean; researchCheckpoint?: ResearchCheckpointSink; mode?: string; } export interface DelegateChildBrowserAssistance { waitId: string; reason: string; browserSessionId: string; url: string; } export interface DelegateChildRunResult { summary: string; finalAnswer?: string; toolIterations: number; messages: AgentMessage[]; status: 'success' | 'failed' | 'cancelled' | 'partial'; stopReason: DelegationStopReason; budget: ReturnType['snapshot']>; handoff: { requested: boolean; completed: boolean; summary: string; }; verification?: Awaited>; browserAssistance?: DelegateChildBrowserAssistance; } export interface DelegateChildHandle { run(): Promise; abort(reason?: AgentAbortReason): void; } /** Leaf workers use the same execution, transcript and verification harness as foreground turns. */ export declare function createDelegateChildHandle(options: DelegateChildHandleOptions): DelegateChildHandle;