/** * src/llm/LLMRouter.ts * * Routes LLM requests to the optimal provider chain. Supports per-member * provider preferences and complexity-based routing: * low → Groq (fast/cheap) * medium → configured provider or Groq * high → configured provider or Anthropic (capable) * * Provider modules are loaded lazily — the underlying SDK import happens * on first use, not when LLMRouter is imported. */ import type { ILLMProvider } from './ILLMProvider.ts'; import type { LLMConfig, LLMRequest, ComplexityTier } from './types.ts'; import type { ProviderName } from '../members/types.ts'; /** * Heuristic complexity scorer for LLM requests. * * Evaluates message count, tool count, and chain‑of‑thought markers * to classify a request as low, medium, or high complexity. * Used by LLMRouter.route() when strategy is 'dynamic'. */ export declare class ComplexityScorer { /** * Score a request and return the complexity tier. * * Rules: * - high: >3 tools or system prompt contains chain‑of‑thought markers * - medium: >5 messages or any tools present * - low: else */ score(request: LLMRequest): ComplexityTier; } /** * Static router that creates and caches LLM providers. * * Supports three modes: * - **create** — single provider or default provider chain * - **createForMember** — per‑member provider chain with preferred + fallback * - **route** — complexity‑based dynamic provider selection * * Provider modules are lazy‑loaded (dynamic import on first use), * so importing LLMRouter does not pull in provider SDKs. */ export declare class LLMRouter { /** Single source of truth for --provider validation (see run.ts) */ static knownProviders(): string[]; private static providerFactories; private static instances; private static initPromises; private static config; /** * Create a single provider or a default provider chain from config. * If config specifies a known provider, returns that provider. * Otherwise builds a ProviderChain with fallback order: groq → openai → ollama. */ static create(config: LLMConfig): Promise; static fromConfig(config: LLMConfig): Promise; /** * Instantiate providers for pre-ordered entries, skipping unknown names * and failed inits. Shared by fromConfig (priority order) and * createForMember (member-preference order) — the only difference between * the two paths is the entry ordering, decided by the caller. */ private static buildChainFromEntries; /** * Create a per‑member provider chain with the member's preferred provider first, * then fallback providers (groq, openai, ollama) in order. * Used when running individual Society members via `agenthood run `. */ static createForMember(preferredProvider: ProviderName, config: LLMConfig): Promise; private static entryToConfig; /** * Route a request to a provider based on complexity score. * * When strategy is 'dynamic', uses ComplexityScorer to select: * - low → Groq (fast/cheap) * - medium → configured provider or Groq * - high → Anthropic (capable) or configured provider * * When strategy is 'static' (default), delegates to create(). */ private static tierProviders; static route(request: LLMRequest, config: LLMConfig): Promise; private static resolveSingle; /** * Get a cached provider instance or initialise it on first access. * Deduplicates concurrent init requests so the same provider is * only constructed once even if multiple callers race. */ private static getOrInit; /** * Clear cached provider instance and reinitialize with new config. * Used for hot-reload after API key rotation. */ /** Cached per-provider instance for single-provider use (health probes); * unlike reinitializeProvider this reuses an existing instance. */ static getProvider(name: string, config: LLMConfig): Promise; static reinitializeProvider(name: string, config: LLMConfig): Promise; private static buildChainConfig; /** * Build the default ProviderChain with fallback order: groq → openai → ollama. * Used when config does not specify a single provider or when member * provider initialisation fails. */ private static buildDefaultChain; private static buildProviderChain; } //# sourceMappingURL=LLMRouter.d.ts.map