import { type CostBudgetTracker, type CostLimitContext } from "./cost-budget.js"; import type { ModelMessage, ModelProvider, ModelUsage, ThinkingLevel } from "./model.js"; import type { CapabilityPolicy } from "./policy.js"; import type { SandboxEnv } from "./sandbox.js"; import type { ToolCall, ToolCallResult, ToolDef } from "./tools.js"; import type { FabricEvent, JournalCallbacks, JsonObject, ResultValidator, SessionEntry, SessionEntryType, StreamChunkStore } from "./types.js"; import type { CostAttribution } from "./cost-budget.js"; export interface AgentLoopRuntime { readonly name: string; runPrompt(input: PromptRunInput): Promise; } export interface PromptRunInput { sessionId: string; text: string; messages: ModelMessage[]; tools: Map; sandbox: SandboxEnv; model?: string; /** Effective reasoning effort resolved from the prompt/session/agent scope chain. */ thinkingLevel?: ThinkingLevel; modelProvider?: ModelProvider; toolCalls?: ToolCall[]; maxIterations?: number; modelTimeoutMs?: number; modelRetries?: number; modelRetryDelayMs?: number; signal?: AbortSignal; policy?: CapabilityPolicy; approvalTimeoutMs?: number; /** Optional shared cost budget for the session. */ costBudget?: CostBudgetTracker; /** * Pause-and-wait approval for a cost-limit hit. Required when * `costBudget.onExceed === 'approve'`. Resolves true on approve, false on * deny. If absent, the loop falls back to `'throw'` behavior. */ requestCostLimitApproval?: (ctx: CostLimitContext) => Promise; /** Optional durable operation id for turn journaling and recovery. */ operationId?: string; /** Optional journal callbacks for turn-phase durability tracking. */ journal?: JournalCallbacks; /** * Optional durable store for stream chunk segments. When provided, the * streaming path buffers chunks and flushes them every 3s so interrupted * streams can be reconstructed on recovery. */ streamChunkStore?: StreamChunkStore; /** Optional result validator. When set, the loop injects `finish`/`give_up` tools. */ resultValidator?: ResultValidator; /** * Opaque provider affinity key (`aff_`). Forwarded to model providers * as `sessionId` where supported (e.g. Bedrock prompt caching). */ affinityKey?: string; /** Optional agent id for cost attribution. */ agentId?: string; /** Optional tenant id for cost attribution. */ tenantId?: string; /** Canonical user messages admitted while this response is live. */ takeSteeringMessages?: () => Promise; /** Refresh hook-rendered resources immediately before each provider turn. */ refreshTurn?: () => Promise<{ model?: string; thinkingLevel?: ThinkingLevel; modelProvider?: ModelProvider; tools?: Map; sandbox?: SandboxEnv; policy?: CapabilityPolicy; systemInstruction?: string; }>; /** Persist cache-safe conditional tools on the result that unlocked them. */ recordToolAdditions?: (toolCallId: string, names: string[]) => Promise; executeToolCalls(calls: ToolCall[], policy?: CapabilityPolicy, approvalTimeoutMs?: number, attribution?: CostAttribution): Promise; recordEntry(type: SessionEntryType, data?: JsonObject): Promise; emit(type: FabricEvent["type"], data?: JsonObject): Promise; } export interface PromptRunResult { text: string; raw: unknown; usage?: ModelUsage; /** Populated when the `finish` tool was used to produce a validated result. */ validatedResult?: unknown; } export declare class NativeLoopRuntime implements AgentLoopRuntime { readonly name = "native"; runPrompt(input: PromptRunInput): Promise; private executeModelToolCalls; } export declare const defaultLoopRuntime: NativeLoopRuntime; //# sourceMappingURL=loop.d.ts.map