/**
 * Agent Executor Module
 *
 * Implements the core agentic loop for processing user messages,
 * both sequential and streaming. Handles tool execution rounds,
 * token counting, cost tracking, and context management.
 *
 * @module agent/execution
 */
import { CodeBuddyClient, CodeBuddyMessage } from "../../codebuddy/client.js";
import { ChatEntry, StreamingChunk } from "../types.js";
import { ToolHandler } from "../tool-handler.js";
import { ToolSelectionStrategy } from "./tool-selection-strategy.js";
import { StreamingHandler } from "../streaming/index.js";
import { ContextManagerV2 } from "../../context/context-manager-v2.js";
import { TokenCounter } from "../../utils/token-counter.js";
import type { LaneQueue } from "../../concurrency/lane-queue.js";
import type { MiddlewarePipeline } from "../middleware/index.js";
/**
 * Dependencies injected into the AgentExecutor
 */
export interface ExecutorDependencies {
    /** API client for LLM communication */
    client: CodeBuddyClient;
    /** Dispatcher for tool execution */
    toolHandler: ToolHandler;
    /** RAG-based tool selection for query optimization */
    toolSelectionStrategy: ToolSelectionStrategy;
    /** Handles streaming response accumulation */
    streamingHandler: StreamingHandler;
    /** Manages context window and message compression */
    contextManager: ContextManagerV2;
    /** Counts tokens for cost calculation */
    tokenCounter: TokenCounter;
    /** Optional lane queue for serialized tool execution */
    laneQueue?: LaneQueue;
    /** Lane ID for tool execution serialization (defaults to 'default') */
    laneId?: string;
    /** Optional middleware pipeline for composable loop control */
    middlewarePipeline?: MiddlewarePipeline;
}
/**
 * Runtime configuration for the AgentExecutor
 */
export interface ExecutorConfig {
    /** Maximum tool execution rounds before stopping (prevents infinite loops) */
    maxToolRounds: number;
    /** Returns true if current model is a Grok model (enables web search) */
    isGrokModel: () => boolean;
    /** Records token usage for cost tracking */
    recordSessionCost: (input: number, output: number) => void;
    /** Returns true if session cost limit has been reached */
    isSessionCostLimitReached: () => boolean;
    /** Returns current accumulated session cost in USD */
    getSessionCost: () => number;
    /** Returns maximum allowed session cost in USD */
    getSessionCostLimit: () => number;
}
/**
 * AgentExecutor implements the core agentic loop
 *
 * The agentic loop follows this pattern:
 * 1. Select relevant tools for the query (RAG-based)
 * 2. Send message to LLM with selected tools
 * 3. If LLM requests tool calls, execute them
 * 4. Send tool results back to LLM
 * 5. Repeat until LLM responds without tool calls or max rounds reached
 *
 * Supports both sequential (processUserMessage) and streaming
 * (processUserMessageStream) execution modes.
 */
export declare class AgentExecutor {
    private deps;
    private config;
    constructor(deps: ExecutorDependencies, config: ExecutorConfig);
    /**
     * Build a MiddlewareContext from current loop state.
     */
    private buildMiddlewareContext;
    /**
     * Execute a tool call, optionally through the LaneQueue for serialization.
     * Read-only tools (grep, glob, read_file) run in parallel; mutating tools run serially.
     */
    private executeToolViaLane;
    /**
     * Process a user message sequentially (non-streaming)
     *
     * @param message - The user's input message
     * @param history - Chat history array (modified in place)
     * @param messages - LLM message array (modified in place)
     * @returns Array of new chat entries created during this turn
     */
    processUserMessage(message: string, history: ChatEntry[], messages: CodeBuddyMessage[]): Promise<ChatEntry[]>;
    /**
     * Process a user message with streaming response
     *
     * Yields chunks as they arrive from the LLM, enabling real-time UI updates.
     * Chunk types: 'content', 'tool_calls', 'tool_result', 'token_count', 'done'
     *
     * @param message - The user's input message
     * @param history - Chat history array (modified in place)
     * @param messages - LLM message array (modified in place)
     * @param abortController - Controller to cancel the operation
     * @yields Streaming chunks for UI consumption
     */
    processUserMessageStream(message: string, history: ChatEntry[], messages: CodeBuddyMessage[], abortController: AbortController | null): AsyncGenerator<StreamingChunk, void, unknown>;
}
