UNPKG

agentjs-core

Version:

A comprehensive agent-based modeling framework with built-in p5.js visualization

183 lines 4.89 kB
/** * AgentManager - Centralized management system for agents */ import { EventEmitter } from 'eventemitter3'; import type { Agent } from './agents/Agent'; import type { AgentId, AgentState } from '../types/core'; /** Agent collection configuration */ export interface AgentManagerConfig { readonly maxAgents: number; readonly enablePerformanceMonitoring: boolean; readonly performanceWarningThreshold: number; readonly enableObjectPooling: boolean; readonly poolSize: number; } /** Agent query options */ export interface AgentQueryOptions { readonly state?: AgentState; readonly property?: string; readonly propertyValue?: any; readonly limit?: number; readonly offset?: number; } /** Performance metrics */ export interface PerformanceMetrics { readonly agentCount: number; readonly activeAgents: number; readonly lastStepTime: number; readonly averageStepTime: number; readonly memoryUsage: number; readonly operationsPerSecond: number; } /** Bulk operation result */ export interface BulkOperationResult { successful: number; failed: number; errors: Array<{ agentId: AgentId; error: string; }>; } /** * AgentManager - Centralized agent management system * * Features: * - O(1) agent lookup by ID * - Bulk operations for efficiency * - Performance monitoring and warnings * - Memory management with object pooling preparation * - Iterator patterns for efficient processing * - State-based filtering and queries * * Educational Context: Manages the community population, * allowing efficient operations on large groups while * maintaining individual agent tracking and performance. */ export declare class AgentManager extends EventEmitter { /** Agent storage with O(1) lookup */ private agents; /** Agents indexed by state for efficient filtering */ private agentsByState; /** Manager configuration */ private config; /** Performance tracking */ private performanceMetrics; private stepTimes; private lastStepStart; /** Object pool for reuse (preparation for future optimization) */ private _objectPool; constructor(config?: Partial<AgentManagerConfig>); /** * Add agent to manager */ addAgent(agent: Agent): void; /** * Remove agent from manager */ removeAgent(agentId: AgentId): boolean; /** * Get agent by ID */ getAgent(agentId: AgentId): Agent | undefined; /** * Check if agent exists */ hasAgent(agentId: AgentId): boolean; /** * Get all agents */ getAllAgents(): ReadonlyArray<Agent>; /** * Get agents by state */ getAgentsByState(state: AgentState): ReadonlyArray<Agent>; /** * Get active agents only */ getActiveAgents(): ReadonlyArray<Agent>; /** * Get agent count */ getAgentCount(): number; /** * Get active agent count */ getActiveAgentCount(): number; /** * Query agents with filters */ queryAgents(options?: AgentQueryOptions): ReadonlyArray<Agent>; /** * Add multiple agents efficiently */ addAgents(agents: Agent[]): BulkOperationResult; /** * Remove multiple agents efficiently */ removeAgents(agentIds: AgentId[]): BulkOperationResult; /** * Step all active agents */ stepAll(): void; /** * Clear all agents */ clear(): void; /** * Get performance metrics */ getPerformanceMetrics(): PerformanceMetrics; /** * Get manager configuration */ getConfig(): AgentManagerConfig; /** * Get object pool size (for future optimization) */ getObjectPoolSize(): number; /** * Update manager configuration */ updateConfig(newConfig: Partial<AgentManagerConfig>): void; /** * Create iterator for efficient processing */ iterateAgents(state?: AgentState): Generator<Agent, void, unknown>; /** * Create async iterator for non-blocking processing */ iterateAgentsAsync(state?: AgentState, batchSize?: number, delayMs?: number): AsyncGenerator<Agent[], void, unknown>; /** * Handle agent state changes */ private handleAgentStateChange; /** * Add agent to state index */ private addToStateIndex; /** * Remove agent from state index */ private removeFromStateIndex; /** * Update performance metrics */ private updateMetrics; /** * Record step execution time */ private recordStepTime; /** * Estimate memory usage */ private estimateMemoryUsage; /** * Emit performance warning */ private emitPerformanceWarning; /** * Reset the agent manager to initial state */ reset(): void; } //# sourceMappingURL=AgentManager.d.ts.map