/** Zoe Core — THE Agent Loop (single implementation) */ import type { Message, StepResult, ToolCall, Usage, ApproveToolFn, PermissionLevel } from "./types.js"; import type { LLMProvider } from "../providers/types.js"; import type { ToolDefinition } from "../tools/interface.js"; import type { HookExecutor } from "./hooks.js"; import type { Middleware } from "./middleware.js"; export interface ProviderFactory { resolve(skillName?: string): Promise<{ provider: LLMProvider; model: string; }>; restore(): void; } export interface AgentLoopOptions { provider: LLMProvider; model: string; messages: Message[]; toolDefs: ToolDefinition[]; systemPrompt?: string; skillCatalog?: string; maxSteps: number; hooks: HookExecutor; signal?: AbortSignal; config?: Record; metadata?: Record; onStep?: (step: StepResult) => void; /** Opt into token streaming (provider.chatStream). Off → always chat(). */ stream?: boolean; providerFactory?: ProviderFactory; middleware?: Middleware[]; approveTool?: ApproveToolFn; permissionLevel?: PermissionLevel; autoConfirm?: boolean; } export interface AgentLoopError { message: string; code: string; retryable: boolean; provider?: string; tool?: string; } export interface AgentLoopResult { messages: Message[]; steps: StepResult[]; toolCalls: ToolCall[]; usage: Usage; finishReason: "stop" | "max_steps" | "error" | "aborted"; error?: AgentLoopError; } /** * Run the Zoe agent loop - THE single implementation. * * This is the canonical agent loop that all other entry points (createAgent, * generateText, streamText, CLI Agent) will delegate to. It handles: * * - Multi-step reasoning with tool execution * - Provider resolution (including per-skill switching via providerFactory) * - System prompt injection * - Abort signal handling * - Hook execution * - Usage estimation * - Structured error reporting * - Middleware pipeline (when provided) * * @param options - Agent loop configuration * @returns AgentLoopResult with messages, steps, tool calls, usage, and finish reason */ export declare function runAgentLoop(options: AgentLoopOptions): Promise;