/** * Adapter Registry -- Routes agent requests to the correct adapter * * The registry is the single entry point the SwarmOrchestrator uses. * It manages multiple adapters, routes requests based on agent ID patterns, * and provides unified agent discovery across all registered adapters. * * @module AdapterRegistry * @version 1.0.0 */ import type { IAgentAdapter, AdapterConfig, AdapterRoute, RegistryConfig, AgentPayload, AgentContext, AgentResult, AgentInfo, AdapterEventHandler, AdapterEventType } from '../types/agent-adapter'; import type { CircuitBreakerConfig, CircuitState } from '../lib/circuit-breaker'; /** * Factory function that creates an adapter instance on demand. * Used with registerDeferred() for lazy initialization. */ export type AdapterFactory = () => IAgentAdapter; /** * Configurable retry behaviour for adapter execution. * * The policy uses exponential backoff with optional jitter. * Only errors marked `recoverable` in the {@link AgentResult} trigger a retry. */ export interface RetryPolicy { /** Maximum number of retry attempts (0 = no retries, default). */ maxRetries: number; /** Base delay in ms before the first retry (doubled each attempt). */ baseDelayMs: number; /** Maximum delay cap in ms. */ maxDelayMs: number; /** Optional fallback adapter name to try when all retries are exhausted. */ fallbackAdapter?: string; } /** * Central registry that manages multiple agent framework adapters and * routes execution requests to the correct one. * * Supports pattern-based routing, automatic prefix detection, default * adapter fallback, agent caching, unified discovery, and lifecycle events. * * @example * ```typescript * import { AdapterRegistry, LangChainAdapter, CustomAdapter } from 'network-ai'; * * const registry = new AdapterRegistry(); * await registry.addAdapter(new LangChainAdapter()); * await registry.addAdapter(new CustomAdapter()); * * // Route by prefix: "lc:research" -> LangChainAdapter * registry.addRoute({ pattern: 'lc:*', adapterName: 'langchain' }); * * const result = await registry.executeAgent('lc:research', payload, context); * ``` */ export declare class AdapterRegistry { private adapters; private routes; private defaultAdapterName; private eventHandlers; private agentCache; private deferredFactories; /** Opt-in retry policy for adapter execution. */ private retryPolicy; /** Per-adapter circuit breakers. */ private circuitBreakers; /** Circuit breaker configuration applied to all new breakers. */ private circuitBreakerConfig; /** Ordered list of fallback adapter names tried when the primary circuit opens. */ private fallbackChain; constructor(config?: RegistryConfig & { retryPolicy?: Partial; circuitBreaker?: CircuitBreakerConfig; fallbackChain?: string[]; }); /** * Update the retry policy at runtime. */ setRetryPolicy(policy: Partial): void; /** * Update the circuit breaker configuration at runtime. * Only affects breakers created after this call. */ setCircuitBreakerConfig(config: CircuitBreakerConfig): void; /** * Return the current state of the circuit breaker for a given adapter. * Returns `'CLOSED'` if no breaker has been created yet (no traffic). */ getCircuitState(adapterName: string): CircuitState; /** * Force-reset the circuit breaker for a given adapter to CLOSED. * Useful for manual recovery or tests. */ resetCircuit(adapterName: string): void; /** Get or lazily create the circuit breaker for `adapterName`. @internal */ private getBreaker; /** * Register an adapter with the registry. * Call this for each agent framework you want to support. */ registerAdapter(adapter: IAgentAdapter): void; /** * Initialize a registered adapter with its configuration */ initializeAdapter(adapterName: string, config?: AdapterConfig): Promise; /** * Register + initialize in one call (convenience) */ addAdapter(adapter: IAgentAdapter, config?: AdapterConfig): Promise; /** * Remove an adapter and shut it down */ removeAdapter(adapterName: string): Promise; /** * Register an adapter factory for deferred (lazy) initialization. * The adapter instance is created and initialized only when first needed. * @param name Unique adapter name * @param factory Function that creates the adapter instance * @param config Configuration to pass during initialization */ registerDeferred(name: string, factory: AdapterFactory, config?: AdapterConfig): void; /** * Materialize a deferred adapter: create instance, initialize, and move to active map. * @returns The initialized adapter, or null if no deferred factory exists */ private materializeDeferred; /** * Check whether a deferred factory is registered for the given name. */ hasDeferred(name: string): boolean; /** * Get a registered adapter by name */ getAdapter(adapterName: string): IAgentAdapter | undefined; /** * List all registered adapters (active and deferred) */ listAdapters(): Array<{ name: string; version: string; ready: boolean; deferred?: boolean; }>; /** * Set the default adapter for unrouted requests */ setDefaultAdapter(adapterName: string): void; /** * Add a routing rule: agent IDs matching the pattern go to the specified adapter. * * Patterns: * "lc:*" -> all agents prefixed with "lc:" go to the LangChain adapter * "autogen:*" -> AutoGen agents * "crew:*" -> CrewAI agents * "*" -> catch-all * "data_analyst" -> exact match */ addRoute(route: AdapterRoute): void; /** * Resolve which adapter should handle a given agent ID */ resolveAdapter(agentId: string): IAgentAdapter | null; /** * Async version of resolveAdapter that materializes deferred adapters on demand. * Prefer this over resolveAdapter() when deferred factories may be registered. */ resolveAdapterAsync(agentId: string): Promise; private matchPattern; /** * Execute an agent task, automatically routing to the correct adapter. * This is the primary method the SwarmOrchestrator calls. */ executeAgent(agentId: string, payload: AgentPayload, context: AgentContext): Promise; /** * Execute with exponential-backoff retries for recoverable errors. */ private executeWithRetry; /** * Single adapter execution attempt with event emission. */ private executeOnce; /** * Discover all agents across all registered adapters */ discoverAgents(): Promise; /** * Check if any adapter can handle a specific agent */ isAgentAvailable(agentId: string): Promise; healthCheck(): Promise>; on(event: AdapterEventType, handler: AdapterEventHandler): void; off(event: AdapterEventType, handler: AdapterEventHandler): void; private emit; /** * Shut down all adapters and clear the registry */ shutdownAll(): Promise; } export declare function getRegistry(config?: RegistryConfig): AdapterRegistry; //# sourceMappingURL=adapter-registry.d.ts.map