UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

40 lines (39 loc) • 3.35 kB
/** * The leg's announcement of a walked model request — `model.fallback` (audience `user`) on the main lane, the person's own request; * `model.fallback_side_call` (audience `operator`, 7.70.0) on a side lane (compaction, classifier, extension, advisor), which does not * change who answers the person: the requested model could not serve * (or was not sent: its own route was refused before sending, `route_refused`), and either a fallback model answered * (`outcome: "served"`) or none could (`"exhausted"`). Read off the answer at the accounting points that read every answer (the * main loop's, and the side-call lanes' book), so the lane that made the call is named: the marker for a walk that tried a hop, * and the statement of a walk that sent none (every hop it reached refused before sending — `exhausted` with no hop tried, no * `to`). Told ONCE PER SESSION PER (from, lane, to, reason, outcome): the delivery throat's fact key, against the told record the seat is * built over (a leg's own session's; a compaction pass outside a run keeps one in memory). The fact ends when the requested model * itself answers ON THE LANE THE WALK WAS TOLD ON: the same point reads that answer ({@link ModelFallbackSeat.observe}'s `reply`), and every * walk away from that model on that lane is released, so the next time it cannot serve there it is told again. A lane's answer says nothing of * another's (a rate limit that refuses the main requests and lets a classifier's small ones through leaves the main lane's walk standing). * The main lane's operational alert for a * walk that sent no hop keeps its own unit, once per seat per walk, beside the run's first-switch record it stands in for. */ import { type EngineNotice, type NoticeTold } from "../engine-notice.js"; import type { Model } from "../../internal/llm.js"; import type { ServedReading } from "../../brain/model-lane.js"; import type { UsageLane } from "./side-call-account.js"; /** Which call of the leg the request was: the lane it is booked on. */ export type ModelFallbackLane = UsageLane; /** What a reply says of whether the model answered: its stop reason, and whether a torn stream's partial text was finalized into it. */ export interface ModelReply { readonly stopReason?: string; readonly partialFinalized?: boolean; } export interface ModelFallbackSeat { /** Announce a walk on the answer to a request for `requested` on `lane`, unless this leg already announced the same walk; an answer * with no walk that is the requested model's own — `reply` is an answer ({@link answeredWith}; absent: the message came from no * model call, or the call made none) — ends the fact that it could not serve. */ observe(lane: ModelFallbackLane, requested: Model, reading: ServedReading, reply: ModelReply | undefined): void; } /** `told` is the session's told record the notice is judged against; `alert` is the leg's operational alert for a walk that sent no hop * on the main lane (a walk that tried one has its own, with the switch it records): told the announced sentence, once per seat per walk. */ export declare function createModelFallbackSeat(onNotice: ((notice: EngineNotice) => void) | undefined, told: NoticeTold, ids: { sessionId: string; runId?: string; }, alert?: (sentence: string) => void): ModelFallbackSeat;