export interface TextBlock { readonly type: "text"; readonly text: string; } export interface ToolUseBlock { readonly type: "tool_use"; readonly id: string; readonly name: string; readonly input: Record; } export interface ToolResultBlock { readonly type: "tool_result"; readonly tool_use_id: string; /** Stringified result payload (JSON or plain text). */ readonly content: string; /** Set when the tool failed — lets the model recover instead of us failing. */ readonly is_error?: boolean; } export type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock | Record; /** A message in the running conversation. `content` is a string or blocks. */ export interface AgentMessage { readonly role: "user" | "assistant"; readonly content: string | readonly ContentBlock[]; } /** Anthropic tool definition (forwarded to the proxy in `tools`). */ export interface AgentToolSpec { readonly name: string; readonly description: string; readonly input_schema: Record; } export type AgentTurnStopReason = "end_turn" | "max_tokens" | "stop_sequence" | "tool_use"; /** One per-turn result from the proxy (`aithos.compute_invoke_turn`). */ export interface AgentTurnResult { readonly content: readonly ContentBlock[]; readonly stopReason: AgentTurnStopReason; readonly usage: { readonly inputTokens: number; readonly outputTokens: number; }; /** Microcredits charged for THIS turn (cumulative billing — HANDOFF §1). */ readonly creditsCharged?: number; readonly walletBalance?: number; } /** Extract the tool_use blocks from a turn's content (in order). */ export declare function extractToolUseBlocks(content: readonly ContentBlock[]): readonly ToolUseBlock[]; /** Concatenate the text blocks of a turn into a single string. */ export declare function extractText(content: readonly ContentBlock[]): string; /** Build a single tool_result block. */ export declare function toolResult(toolUseId: string, payload: string, isError?: boolean): ToolResultBlock; /** Build the user message carrying one or more tool_result blocks. */ export declare function buildToolResultMessage(results: readonly ToolResultBlock[]): AgentMessage; export type LoopStopReason = "end_turn" | "max_tokens" | "stop_sequence" | "max_iterations"; export interface ToolCallTrace { readonly name: string; readonly ok: boolean; readonly turn: number; } export interface AggregateUsage { readonly inputTokens: number; readonly outputTokens: number; } export interface DispatchOutcome { readonly payload: string; readonly isError: boolean; } export interface LocalAgenticLoopResult { readonly finalContent: string; readonly stopReason: LoopStopReason; /** Number of proxy turns performed (each is a billed call). */ readonly iterations: number; readonly usage: AggregateUsage; readonly toolCalls: readonly ToolCallTrace[]; /** Sum of per-turn `creditsCharged` (HANDOFF §1: per-turn cumulative billing). */ readonly creditsCharged: number; /** Wallet balance reported by the LAST turn (0 if none reported). */ readonly walletBalance: number; } export interface LocalAgenticLoopArgs { /** Initial conversation (copied internally; not mutated by the caller). */ readonly messages: readonly AgentMessage[]; /** Hard cap on proxy turns. */ readonly maxIterations: number; /** One signed proxy turn. Receives the running message list. */ readonly invokeTurn: (messages: readonly AgentMessage[]) => Promise; /** Execute one tool call LOCALLY (read/write the user's ethos). Async. */ readonly dispatch: (name: string, input: Record) => Promise; } /** * Run the client-side agentic loop. Never throws on tool errors (they become * `tool_result.is_error` so the model can recover); only `invokeTurn` * rejections propagate to the caller (the proxy already refunded that turn). */ export declare function runAgenticLoopLocal(args: LocalAgenticLoopArgs): Promise; //# sourceMappingURL=agent-loop.d.ts.map