/** * Autonomous Agent - provides self-management capabilities for continuously running agents * Handles background processing, self-monitoring, and recovery mechanisms * Enhanced with goal planning and execution capabilities */ import { Agent } from './agent'; import { Tool } from './types'; import { EventEmitter } from 'events'; import { GoalType, Goal, GoalResult } from '../planning/goal-planner'; /** * Configuration for the autonomous agent */ export interface AutonomousAgentConfig { baseAgent: Agent; healthCheckIntervalMinutes?: number; maxConsecutiveErrors?: number; stateStoragePath?: string; enableAutoRecovery?: boolean; enableContinuousMode?: boolean; goalPlanning?: { enabled: boolean; maxSubgoals?: number; maxTasksPerGoal?: number; reflectionFrequency?: number; adaptivePlanning?: boolean; defaultPriority?: number; defaultDeadlineDays?: number; maxConcurrentGoals?: number; persistGoals?: boolean; goalsStoragePath?: string; }; } /** * Options for running a goal */ export interface RunGoalOptions { tools?: Tool[]; maxReflections?: number; reflectAfterTaskCount?: number; stopOnFailure?: boolean; onProgress?: (progress: { goalId: string; subGoalId?: string; taskId?: string; message: string; progress: number; }) => void; } /** * Autonomous Agent that enhances a standard agent with self-management capabilities */ export declare class AutonomousAgent extends EventEmitter { private agent; private logger; private config; private state; private stateFilePath; private healthCheckInterval; private operationQueue; private processingQueue; private running; private goalPlanner; private goalsFilePath; private activeGoals; private recurringGoalTimers; /** * Creates a new autonomous agent * * @param config - Configuration for the autonomous agent */ constructor(config: AutonomousAgentConfig); /** * Sets up goal planning capabilities * * @param agentName - The name of the agent for file naming */ private setupGoalPlanning; /** * Starts the autonomous agent */ start(): void; /** * Stops the autonomous agent */ stop(): void; /** * Adds an operation to the queue * * @param operation - The operation function to queue */ queueOperation(operation: () => Promise): void; /** * Processes the operation queue in a loop */ private processQueueLoop; /** * Recovery mode for handling consecutive errors */ private enterRecoveryMode; /** * Perform health check of the agent */ private performHealthCheck; /** * Load agent state from disk */ private loadState; /** * Save agent state to disk */ private saveState; /** * Run an operation with the underlying agent * * @param taskOrOptions - Task string or options for the agent * @returns Promise resolving to the agent's response */ runOperation(taskOrOptions: string | any): Promise; /** * Get or update the agent's custom state * * @param key - State key * @param value - Optional value to set * @returns The current value for the key */ customState(key: string, value?: T): T | undefined; /** * Get agent status information */ getStatus(): { name: string; running: boolean; lastActive: Date; uptime: number; queueLength: number; operations: { total: number; successful: number; failed: number; successRate: number; }; goals?: { total: number; active: number; completed: number; failed: number; pending: number; recurring: number; }; }; /** * Creates a new goal for the agent to work towards * * @param description - Description of the goal * @param options - Additional goal options * @returns The created goal */ createGoal(description: string, options?: { type?: GoalType; successCriteria?: string[]; priority?: number; deadline?: Date; recurrence?: string; metadata?: Record; executeImmediately?: boolean; tools?: Tool[]; }): Promise; /** * Execute a goal * * @param goalId - ID of the goal to execute * @param options - Execution options * @returns Promise resolving to the execution result */ executeGoal(goalId: string, options?: RunGoalOptions): Promise; /** * Calculate an approximate progress percentage for a goal * * @param goalId - ID of the goal * @param progress - Current progress info * @returns Progress percentage (0-100) */ private calculateProgressPercentage; /** * Sets up a recurring goal with a timer * * @param goalId - ID of the goal * @param recurrencePattern - Recurrence pattern string (e.g., 'every 6 hours') * @param tools - Tools available for this goal */ private setupRecurringGoal; /** * Clear a recurring goal timer * * @param goalId - ID of the goal */ private clearRecurringGoalTimer; /** * Parse a recurrence pattern into milliseconds * * @param pattern - Recurrence pattern string * @returns Milliseconds interval or null if invalid */ private parseRecurrenceInterval; /** * Reset a recurring goal for its next execution * * @param goalId - ID of the goal to reset */ private resetRecurringGoal; /** * Save goals to disk */ private saveGoals; /** * Load goals from disk */ private loadGoals; /** * Gets all goals * * @returns Array of all goals */ getGoals(): Goal[]; /** * Gets a specific goal * * @param goalId - ID of the goal * @returns The goal or undefined if not found */ getGoal(goalId: string): Goal | undefined; /** * Cancels a goal * * @param goalId - ID of the goal to cancel * @returns Whether the goal was successfully cancelled */ cancelGoal(goalId: string): boolean; }