@sema-agent/core
Version:
Stateless, task-oriented AI agent core
18 lines (17 loc) • 1.12 kB
TypeScript
import type { Brain } from "../core/types.js";
/**
* Compose several brains into one with ordered failover (primary → fallbacks).
*
* The happy path streams live from the first brain. A brain is only failed over to the next when it
* fails **before emitting any content** (e.g. the gateway is down / connection refused, OR a
* first-token timeout that fires after the stream opened but before any delta) — a clean upfront
* failure. The leading `start` event is **held back** until the first real content event, so an
* error between `start` and the first delta can still fail over without ever having forwarded a
* (then-duplicated) `start`. Once real content (text/thinking/tool) has streamed, the outcome
* (including a mid-stream error or abort) is propagated rather than restarted, so the consumer never
* sees duplicate `start`/text events. The last brain's result is always final.
*
* Each underlying brain keeps its own retry policy (e.g. `createOpenAIBrain({ maxRetries })`);
* failover is the cross-gateway layer on top.
*/
export declare function createFailoverBrain(brains: Brain[]): Brain;