agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
34 lines • 1.53 kB
TypeScript
/**
* fallbackProvider — convenience for chained fallbacks across N providers.
*
* Pattern: Chain of Responsibility (GoF) over `LLMProvider` instances.
* Role: Outer ring (Hexagonal). Sugar over repeated `withFallback`.
*
* `fallbackProvider(p1, p2, p3)` is equivalent to
* `withFallback(p1, withFallback(p2, p3))` — tries each provider in
* order, advancing on errors that match the (optional) shouldFallback
* predicate. The first success wins; if all fail, the last error throws.
*
* @example
* import { anthropic, openai, mock } from 'agentfootprint/providers';
* import { fallbackProvider } from 'agentfootprint/resilience';
*
* const provider = fallbackProvider(
* anthropic({ apiKey: A }),
* openai({ apiKey: O }),
* mock({ reply: '[degraded] all upstream providers failed' }),
* );
*/
import type { LLMProvider } from '../provider-contract/types.js';
import { type WithFallbackOptions } from './withFallback.js';
export interface FallbackProviderOptions extends WithFallbackOptions {
/** Optional explicit name for the chained provider. */
readonly name?: string;
}
/**
* Compose N providers into a single fallback chain. At least one
* provider is required; throws synchronously on empty input.
*/
export declare function fallbackProvider(...providers: readonly LLMProvider[]): LLMProvider;
export declare function fallbackProvider(options: FallbackProviderOptions, ...providers: readonly LLMProvider[]): LLMProvider;
//# sourceMappingURL=fallbackProvider.d.ts.map