UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

94 lines (93 loc) • 6.29 kB
/** * Which model roles the engine resolves ITSELF at a task's prepare, where, and whether a role that supplies nothing * refuses — one table — and the one question a host asks of it: "will this model face (`{ models, tiers, roles, pricing }`, * what a host hands `new Runner`) make a task's prepare refuse on a role?". * * Each row is a role the engine reads itself at a hop that can refuse; the hop is the engine's own function, the very * one prepare calls — the question below calls it too, so the answer cannot drift from what a task meets, and no * judgment is written twice. A hop is not a copy: `resolveRunModel` (`seat-model-doors.ts`: the task's own model) and * `assertAutoConsolidationWirable` (`memory-consolidation-driver.ts`: the consolidation arming door) — both are called * from `prepare-config-doors.ts`, and the rows stand in the order prepare reaches them. * * `when` says WHAT the hop reads. `per-task`: the face AND the task's own spec (`model`, `modelRole`, `roles`) — a task * that names its model never walks the `default` chain. `deployment`: the face alone — the deployment's own question, asked of every prepare (the deps door) and of * a host-run consolidation, and only a refusal when auto-consolidation is armed (`autoRunOnRecommendation: true`); an * explicit `memoryConsolidationDriver.chat` seat is no part of a face, so a deployment that names one holds a seat the * question does not see. Nothing resolves a role at `new Runner` (it receives the catalog and the tier bindings, which are no * roles): the first refusal on a role comes at the first prepare. * * `absence` says what a row does when its role supplies NO model at all: `throws` — the hop refuses; `falls-back` — the * hop answers "none" and the caller carries on. * * Not rows, on purpose: the auto-mode classifier seat (`classifierSeatModel`) and the next-prompt suggestion pass resolve * a role and take the main model when it supplies none — neither refuses; the `subagent` / `verifier` seats resolve when a * child is spawned, not at the parent's prepare; `sideQuery` and `Runner.compactSession` resolve at the caller's call, on a * model the caller names. A role resolution site that refuses at prepare and is not a row here is a missing row. */ import type { Model } from "../../internal/llm.js"; import type { ModelPricing } from "../pricing.js"; import type { ModelRef, ModelRole, ModelRoles, TaskSpec } from "../types.js"; /** When a row's hop reads its role — see the module note. */ export type RoleResolutionWhen = "per-task" | "deployment"; /** What a row does when its role supplies no model — see the module note. */ export type RoleResolutionAbsence = "throws" | "falls-back"; /** One row: the role, when it is read, the hop that reads it (`file :: function`), and what its absence does. */ export interface RoleResolutionRow { readonly role: ModelRole; readonly when: RoleResolutionWhen; readonly hop: string; readonly absence: RoleResolutionAbsence; } /** The roles the engine resolves itself at prepare — read-only; the table the question below walks, in the order prepare reaches them. */ export declare const ROLE_RESOLUTION_TABLE: readonly [Readonly<{ role: "consolidate"; when: "deployment"; hop: "src/core/runner/memory-consolidation-driver.ts :: assertAutoConsolidationWirable"; absence: "throws"; }>, Readonly<{ role: "default"; when: "per-task"; hop: "src/core/runner/seat-model-doors.ts :: resolveRunModel"; absence: "throws"; }>]; /** The model face the question is asked of — the members a host hands `new Runner` for models: the catalog, the tier bindings over it, the role map, and the price * table (`RunnerDeps.pricing`, which the fast-tier door reads). The question applies the Runner's own catalog door to them (do not pre-expand the tiers). */ export interface ModelFace { models?: Record<string, Model>; tiers?: Record<string, ModelRef>; roles?: ModelRoles; pricing?: Record<string, ModelPricing>; } /** The task a per-task row is asked about: the members of a `TaskSpec` those hops read. Omitted ⇒ a task that names none of them. */ export type ModelFaceTask = Pick<TaskSpec, "model" | "modelRole" | "roles">; export interface ModelFaceOptions { /** The task the per-task rows are asked about (default: a task naming no model and no role). */ spec?: ModelFaceTask; /** Which rows to ask (default `["per-task"]`; add `"deployment"` to ask the consolidation seat as armed). */ when?: readonly RoleResolutionWhen[]; } /** The answer: `ok: true`, or the first row whose hop refuses — its role and the code of the refusal the hop itself throws. */ export type ModelFaceVerdict = { ok: true; } | { ok: false; role: (typeof ROLE_RESOLUTION_TABLE)[number]["role"]; code: string; }; /** * Will a task's prepare refuse on a role resolution, over this model face? Walks the rows of {@link ROLE_RESOLUTION_TABLE} * the options select, in table order (the order prepare reaches them), and asks each row's own hop; the first that throws is * the answer — `{ ok: false, role, code }`, the `code` the hop's refusal carries (nothing is minted here). `{ ok: true }` ⇔ * none refuses. * * Pure: reads the face and the spec, writes nothing; each member is read once, as prepare takes a task's members once, and * the catalog and the role maps are received once before any hop reads them (a role map that is no map refuses before any * role is read, and the first row asked carries that refusal). A face whose catalog `new Runner` would not accept, given the * same models and pricing, is refused as `new Runner` refuses it — thrown, not a verdict. A role that supplies no model is a refusal only where the row's * `absence` says `throws`. A throw that carries no code is not a verdict and is rethrown. * * Whether a task's prepare refuses on a role over a given face is answered here and nowhere else: a host that derives it from * its own copy of the role walk (for example by handing the engine a role map cut down to one key) answers a different * question the day the walk moves. */ export declare function modelFaceResolvable(face: ModelFace, options?: ModelFaceOptions): ModelFaceVerdict;