/** * Agent loop that works with AgentMessage throughout. * Transforms to Message[] only at the LLM call boundary. */ import { type AssistantMessage, EventStream, type ToolResultMessage } from "@leanandmean/ai"; import type { AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, AgentTool, AgentToolCall, StreamFn } from "./types.js"; export type AgentEventSink = (event: AgentEvent) => Promise | void; /** * Start an agent loop with a new prompt message. * The prompt is added to the context and events are emitted for it. */ export declare function agentLoop(prompts: AgentMessage[], context: AgentContext, config: AgentLoopConfig, signal?: AbortSignal, streamFn?: StreamFn): EventStream; /** * Continue an agent loop from the current context without adding a new message. * Used for retries - context already has user message or tool results. * * **Important:** The last message in context must convert to a `user` or `toolResult` message * via `convertToLlm`. If it doesn't, the LLM provider will reject the request. * This cannot be validated here since `convertToLlm` is only called once per turn. */ export declare function agentLoopContinue(context: AgentContext, config: AgentLoopConfig, signal?: AbortSignal, streamFn?: StreamFn): EventStream; export declare function runAgentLoop(prompts: AgentMessage[], context: AgentContext, config: AgentLoopConfig, emit: AgentEventSink, signal?: AbortSignal, streamFn?: StreamFn): Promise; export declare function runAgentLoopContinue(context: AgentContext, config: AgentLoopConfig, emit: AgentEventSink, signal?: AbortSignal, streamFn?: StreamFn): Promise; type ToolCallHooks = Pick; /** * Execute a single, already-resolved tool call through the identical prepare/execute/finalize * pipeline used for model-requested tool calls, emitting the same `tool_execution_*` and * tool-result message events. The tool is supplied directly rather than looked up in the active * tool set, which is what allows harness-only (LLM-invisible) tools to execute. * * The assistant message carrying the tool call is the caller's responsibility to emit; this * function emits everything from `tool_execution_start` through the tool-result `message_end`. * Returns the resulting tool-result message so the caller can splice it into a live turn context. */ export declare function executeHarnessToolCall(tool: AgentTool, toolCall: AgentToolCall, context: AgentContext, assistantMessage: AssistantMessage, hooks: ToolCallHooks, signal: AbortSignal | undefined, emit: AgentEventSink): Promise; export {}; //# sourceMappingURL=agent-loop.d.ts.map