import { AgentOptions, LLMRequestHookPayload, LLMResponseHookPayload, LLMStreamingResponseHookPayload, ToolCallResult, ChatCompletionMessageToolCall, AgentEventStream, LoopTerminationCheckResult, Tool } from '@multimodal/agent-interface'; /** * BaseAgent - Handles all Agent lifecycle-related methods * * This class provides a foundation for agent implementations by managing: * - Lifecycle hooks (onLLMRequest, onLLMResponse, etc.) * - Tool call hooks (onBeforeToolCall, onAfterToolCall, etc.) * - Loop management hooks (onEachAgentLoopStart, onAgentLoopEnd, etc.) * - Termination control (requestLoopTermination, onBeforeLoopTermination) * * Derived classes can override these methods to implement custom behavior * without needing to implement the complete agent functionality. */ export declare abstract class BaseAgent { protected options: T; protected logger: import("@agent-infra/logger/dist/console-logger").ConsoleLogger; private shouldTerminateLoop; constructor(options: T); /** * Control the initialize process, you may need to perform some time-consuming * operations before starting here */ initialize(): void | Promise; /** * Hook called before sending a request to the LLM * This allows subclasses to inspect the request before it's sent * * @param id Session identifier for this conversation * @param payload The complete request payload */ onLLMRequest(id: string, payload: LLMRequestHookPayload): void | Promise; /** * Hook called after receiving a response from the LLM * This allows subclasses to inspect the response before it's processed * * @param id Session identifier for this conversation * @param payload The complete response payload */ onLLMResponse(id: string, payload: LLMResponseHookPayload): void | Promise; /** * Hook called after receiving streaming responses from the LLM * Similar to onLLMResponse, but specifically for streaming * * @param id Session identifier for this conversation * @param payload The streaming response payload */ onLLMStreamingResponse(id: string, payload: LLMStreamingResponseHookPayload): void; /** * Hook called at the beginning of each agent loop iteration * This method is invoked before each iteration of the agent loop starts, * allowing derived classes to perform setup or inject additional context * * @param sessionId The session identifier for this conversation * @returns A promise that resolves when pre-iteration setup is complete */ onEachAgentLoopStart(sessionId: string): void | Promise; /** * Hook called before a tool is executed * This allows subclasses to intercept or modify tool calls before execution * * @param id Session identifier for this conversation * @param toolCall Information about the tool being called * @param args The arguments for the tool call * @returns The possibly modified args for the tool call */ onBeforeToolCall(id: string, toolCall: { toolCallId: string; name: string; }, args: any): Promise | any; /** * Hook called after a tool is executed * This allows subclasses to intercept or modify tool results after execution * * @param id Session identifier for this conversation * @param toolCall Information about the tool that was called * @param result The result of the tool call * @returns The possibly modified result of the tool call */ onAfterToolCall(id: string, toolCall: { toolCallId: string; name: string; }, result: any): Promise | any; /** * Hook called when a tool execution results in an error * This allows subclasses to handle or transform errors from tool calls * * @param id Session identifier for this conversation * @param toolCall Information about the tool that was called * @param error The error that occurred * @returns A potentially modified error or recovery value */ onToolCallError(id: string, toolCall: { toolCallId: string; name: string; }, error: any): Promise | any; /** * Hook called at the end of the agent's execution loop * This method is invoked after the agent has completed all iterations or reached a final answer * * @param id Session identifier for the completed conversation */ onAgentLoopEnd(id: string): void | Promise; /** * Hook called before processing a batch of tool calls * This allows for intercepting and potentially replacing tool call execution * without executing the actual tools - essential for test mocking * * @param id Session identifier for this conversation * @param toolCalls Array of tool calls to be processed * @returns Either undefined (to execute tools normally) or an array of tool call results (to skip execution) */ onProcessToolCalls(id: string, toolCalls: ChatCompletionMessageToolCall[]): Promise | ToolCallResult[] | undefined; /** * Hook called when the agent loop is about to terminate with a final answer * This allows subclasses to inspect the final response and decide whether to: * 1. Allow termination (return {finished: true}) * 2. Force continuation (return {finished: false}) * * This hook is crucial for higher-level agents that need to enforce specific * completion criteria or ensure certain tools are called before finishing. * * @param id Session identifier for this conversation * @param finalEvent The final assistant message event that would end the loop * @returns Decision object indicating whether to finish or continue the loop */ onBeforeLoopTermination(id: string, finalEvent: AgentEventStream.AssistantMessageEvent): Promise | LoopTerminationCheckResult; /** * Request to terminate the agent loop after the current iteration * This allows higher-level agents to control when the loop should end, * even if there are remaining iterations or tool calls * * @returns True if the termination request was set, false if already terminating */ requestLoopTermination(): boolean; /** * Check if loop termination has been requested * Used internally by the loop executor * * @returns True if termination has been requested * @internal */ isLoopTerminationRequested(): boolean; /** * Reset the termination flag when a new run begins * @internal */ protected resetLoopTermination(): void; /** * Get the agent's configuration options * * @returns The agent configuration options used during initialization */ getOptions(): T; /** * Hook called when retrieving tools for the agent * This allows subclasses to filter, modify or enhance the available tools * * IMPORTANT: This hook should not rely heavily on agent's internal state * that changes during execution, as it could lead to inconsistent behavior * between getAvailableTools() calls made before run() and the actual * tools used during run(). * * @param tools The list of registered tools * @returns The filtered or modified list of tools */ onRetrieveTools(tools: Tool[]): Promise | Tool[]; } //# sourceMappingURL=base-agent.d.ts.map