@continue-reasoning/agent
Version:
A platform-agnostic AI agent framework for building autonomous AI agents with tool execution capabilities
182 lines • 5.54 kB
TypeScript
/**
* @fileoverview Core Tool Scheduler Implementation
*
* This module provides the core tool scheduling and execution system for AI agents.
* It manages tool lifecycle, execution state, confirmation workflows, and error handling.
* The implementation references the core package patterns but uses our interface system.
*/
import { IToolScheduler, IToolSchedulerConfig, IToolCallRequestInfo, IToolCall, ITool, ToolConfirmationOutcome, ToolConfirmationPayload } from './interfaces.js';
/**
* Core tool scheduler implementation
*
* This class manages the complete lifecycle of tool execution including:
* - Request validation and scheduling
* - Confirmation workflows for destructive operations
* - Parallel and sequential execution management
* - Error handling and retry logic
* - State tracking and event emission
*
* The implementation follows these principles:
* - Non-blocking operation with async/await patterns
* - Comprehensive state management for all tool calls
* - Flexible confirmation system for user safety
* - Robust error handling with proper cleanup
* - Event-driven architecture for monitoring
*
* @example
* ```typescript
* const scheduler = new CoreToolScheduler({
* toolRegistry: toolRegistryPromise,
* outputUpdateHandler: (id, output) => console.log(`Tool ${id}: ${output}`),
* onAllToolCallsComplete: (completed) => console.log('All tools done'),
* });
*
* await scheduler.schedule([toolCallRequest], abortSignal);
* ```
*/
export declare class CoreToolScheduler implements IToolScheduler {
private config;
/** Map of tool call IDs to their current state */
private toolCalls;
/** Current execution state */
private isCurrentlyRunning;
/** Available tools registry */
private toolRegistry;
/** Promise that resolves when registry is ready */
private registryReady;
/** Abort controller for canceling all operations */
private abortController?;
constructor(config: IToolSchedulerConfig & {
toolRegistry?: Promise<Map<string, ITool>>;
});
/**
* Schedule tool call(s) for execution
*
* This is the main entry point for tool execution. It processes requests,
* validates tools, handles confirmations, and manages execution lifecycle.
*
* @param request - Single tool call or array of tool calls
* @param signal - Abort signal for cancellation
*/
schedule(request: IToolCallRequestInfo | IToolCallRequestInfo[], signal: AbortSignal): Promise<void>;
/**
* Handle confirmation response for a tool call
*
* Processes user responses to confirmation prompts and updates
* tool call state accordingly.
*
* @param callId - Tool call identifier
* @param outcome - User's confirmation decision
* @param payload - Optional payload for modifications
*/
handleConfirmationResponse(_callId: string, outcome: ToolConfirmationOutcome, payload?: ToolConfirmationPayload): Promise<void>;
registerTool(tool: ITool): void;
removeTool(toolName: string): boolean;
getTool(name: string): ITool | undefined;
getToolList(): ITool[];
/**
* Get current tool calls
*
* @returns Array of all current tool calls
*/
getCurrentToolCalls(): IToolCall[];
/**
* Check if scheduler is currently running
*
* @returns True if scheduler is processing tool calls
*/
isRunning(): boolean;
/**
* Cancel all pending tool calls
*
* Cancels all tool calls that are not yet completed and cleans up resources.
*
* @param reason - Reason for cancellation
*/
cancelAll(reason: string): void;
/**
* Validate all tool call requests
*/
private validateToolCalls;
/**
* Validate a single tool call request
*/
private validateSingleToolCall;
/**
* Resolve tool instance for a request
*/
private resolveToolForRequest;
/**
* Handle confirmations for tools that require them
*/
private handleConfirmations;
/**
* Execute all approved (scheduled) tools
*/
private executeApprovedTools;
/**
* Execute a single tool call
*/
private executeToolCall;
/**
* Approve and execute a waiting tool call
*/
private approveAndExecuteToolCall;
/**
* Handle modification request from user
*/
private handleModificationRequest;
/**
* Cancel a tool call
*/
private cancelToolCall;
/**
* Cancel tool call synchronously
*/
private cancelToolCallSync;
/**
* Handle tool call error
*/
private handleToolCallError;
/**
* Handle scheduling error
*/
private handleSchedulingError;
/**
* Wait for all tool calls to complete
*/
private waitForCompletion;
/**
* Check if there are incomplete tool calls
*/
private hasIncompleteToolCalls;
/**
* Check if tool call is completed
*/
private isCompletedToolCall;
/**
* Get tool calls by status
*/
private getToolCallsByStatus;
/**
* Get completed tool calls
*/
private getCompletedToolCalls;
/**
* Notify about output updates
*/
private notifyOutputUpdate;
/**
* Notify about tool calls update
*/
private notifyUpdate;
/**
* Notify about completion
*/
private notifyCompletion;
/**
* Wait for specified time
*/
private wait;
}
//# sourceMappingURL=coreToolScheduler.d.ts.map