/** * Agent Executor * * Implements the core agent loop: Observe -> Think -> Act -> Evaluate * Handles LLM integration, tool execution, and termination conditions. */ import { IAgentState, IAgentExecutionResult, IRunAgentOptions, IDefinedAgent, IConversationMessage, ITokenUsage, ILLMConfig } from './types'; import { ToolRegistry } from './tool-registry'; import { IAgentContextServices } from './agent-context'; /** * LLM Provider interface * Abstracts different LLM providers (Anthropic, OpenAI, etc.) */ export interface ILLMProvider { /** Generate a response with optional tool use */ generate(options: { messages: IConversationMessage[]; systemPrompt: string; tools?: any[]; maxTokens?: number; temperature?: number; stopSequences?: string[]; }): Promise; } /** * LLM response structure */ export interface ILLMResponse { /** Generated content */ content: string; /** Tool calls requested by LLM */ toolCalls?: Array<{ id: string; name: string; input: Record; }>; /** Whether the response is complete or needs tool results */ stopReason: 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence'; /** Token usage */ usage: ITokenUsage; } /** * Stub LLM Provider (for testing until real providers are connected) */ export declare class StubLLMProvider implements ILLMProvider { generate(options: { messages: IConversationMessage[]; systemPrompt: string; tools?: any[]; }): Promise; } /** * Anthropic Claude LLM Provider */ export declare class AnthropicProvider implements ILLMProvider { private apiKey; private baseUrl; private model; private timeout; constructor(config: ILLMConfig); generate(options: { messages: IConversationMessage[]; systemPrompt: string; tools?: any[]; maxTokens?: number; temperature?: number; stopSequences?: string[]; }): Promise; } /** * OpenAI LLM Provider */ export declare class OpenAIProvider implements ILLMProvider { private apiKey; private baseUrl; private model; private timeout; constructor(config: ILLMConfig); generate(options: { messages: IConversationMessage[]; systemPrompt: string; tools?: any[]; maxTokens?: number; temperature?: number; stopSequences?: string[]; }): Promise; } /** * Create LLM provider based on config */ export declare function createLLMProvider(config: ILLMConfig): ILLMProvider; /** * Agent Executor * * Orchestrates the agent loop execution */ export declare class AgentExecutor { private agent; private toolRegistry; private memoryManager; private llmProvider; private llmConfig; private services; private state; private context; private startTime; private options; private terminationConfig; private hooks; private humanInLoop; private streamCallback?; private pendingApproval; private approvalResolver; constructor(agent: IDefinedAgent, toolRegistry: ToolRegistry, services: IAgentContextServices, options: IRunAgentOptions, llmProvider: ILLMProvider, llmConfig: ILLMConfig); /** * Execute the agent */ execute(): Promise; /** * THINK: Call LLM to decide next action */ private think; /** * ACT: Execute a tool call */ private act; /** * Check if execution should terminate */ private shouldTerminate; /** * Check stop conditions against tool result */ private checkStopConditions; /** * Check if output matches expected values */ private matchesOutput; /** * Run hooks for a specific event */ private runHooks; /** * Check if tool requires approval */ private requiresApproval; /** * Request human approval for tool call */ private requestApproval; /** * Handle external approval signal */ handleApproval(approved: boolean, modifiedParams?: Record): void; /** * Handle external stop signal */ handleStop(): void; /** * Handle external pause signal */ handlePause(): void; /** * Handle external resume signal */ handleResume(): void; /** * Emit stream event */ private emit; /** * Build execution result */ private buildResult; /** * Get current state (for status queries) */ getState(): IAgentState; } export default AgentExecutor;