import type { Provider } from "../providers/ProviderTypes.js"; import type { ToolRegistry } from "../tools/ToolRegistry.js"; import type { ToolContext } from "../tools/ToolTypes.js"; import type { CodaliGatewayWorkerTaskRunInput, CodaliGatewayWorkerTaskRunResult, CodaliGatewayWorkerTaskRunner } from "./GatewayStateMachine.js"; /** * Bounded worker-task runner. * * ## Why this exists * * Codali previously executed every gateway worker task by handing it to the * full `CodaliRuntime` agent loop (see `createGatewayTaskRunner` in * `packages/mswarm/src/codali-executor.ts`). That nested one open-ended loop * inside another: the gateway decided how many *rounds* to run, while the * runtime independently decided how many *steps* to take inside each task. * Neither could bound the other, so a single request could fan out * unpredictably and a runaway task was near-impossible to attribute. * * This runner removes the inner loop. Exactly one component - the gateway state * machine - owns iteration. A task here is a single bounded pass: * * 1. ask the model what it needs (one model call) * 2. execute the tool calls it asked for, in parallel where independent * 3. ask the model to turn the results into the task output (one model call) * * There is no step 4 and no "decide whether to keep going". If the evidence is * insufficient, that is the verifier's judgement to make, and the gateway will * schedule another round against `maxIterations`. A worker never extends its * own budget. * * The upper bound on work per task is therefore fixed and knowable: * 2 model calls and `min(remainingToolCalls, MAX_TOOL_CALLS_PER_TASK)` tool * calls. */ /** Hard ceiling on tool calls in a single task, independent of run budget. */ export declare const MAX_TOOL_CALLS_PER_TASK = 8; /** Model calls per task: one to select tools, one to summarize results. */ export declare const MAX_MODEL_CALLS_PER_TASK = 2; export interface LocalGatewayTaskRunnerOptions { provider: Provider; registry: ToolRegistry; toolContext: ToolContext; maxTokens?: number; temperature?: number; /** Observability hook; see `GatewayTracer`. */ onEvent?: (event: LocalGatewayTaskRunnerEvent) => void; } export type LocalGatewayTaskRunnerEvent = { type: "task_start"; taskId: string; workerRole: string; allowedTools: string[]; } | { type: "tool_call"; taskId: string; tool: string; args: unknown; } | { type: "tool_result"; taskId: string; tool: string; ok: boolean; latencyMs: number; errorCode?: string; } | { type: "task_end"; taskId: string; status: "succeeded" | "failed"; toolCallCount: number; modelCallCount: number; durationMs: number; }; export declare class LocalGatewayTaskRunner implements CodaliGatewayWorkerTaskRunner { private readonly options; constructor(options: LocalGatewayTaskRunnerOptions); run(input: CodaliGatewayWorkerTaskRunInput): Promise; } export declare const createLocalGatewayTaskRunner: (options: LocalGatewayTaskRunnerOptions) => LocalGatewayTaskRunner; export declare const isRecordValue: (value: unknown) => value is Record; //# sourceMappingURL=LocalGatewayTaskRunner.d.ts.map