UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

67 lines (66 loc) • 4.74 kB
/** * PrepareTask's ADVISOR phase: whether this leg mounts the `advisor` tool, and what it owes the model about it. In order — * the deployment switch (`RunnerDeps.advisorTool: "disabled"` ignores the spec's advisor model unread); the static verdict * (`advisorAttachVerdict`, the one answer a host's advisor query reads too); then the mount chain — the reserved name, the * advisor's mount row read as if the route attaches (the model and the valve), the conversation's hold (the transcript), the * advisor route (the shared derived-seat pre-flight, posture `detach`, the row's live fact) — and the mount the row judges. * Its answer is the manifest fact, * the person's notice for a reason they are told (root legs only, once per conversation per pair), and the leg's * instruction seat (what the model is owed, against what it was told in the conversation's current segment). * * Runs after the scaffold mounts and before the tool-face fold, so the deferred classification, the prompt and the * manifest see the roster the leg runs with. A leg whose spec names no advisor model and whose conversation never told * the model about one does nothing here and reads nothing. */ import type { SessionTreeEntry } from "../../internal/harness-types.js"; import type { Model } from "../../internal/llm.js"; import type { EngineText } from "../../prompt-assembly/engine-text.js"; import type { CompactionForkContext } from "../auto-compaction.js"; import type { RosterBuilder } from "../tool-roster.js"; import { type RunnerDeps, type TaskSpec } from "../types.js"; import type { WiringAdvisorFact } from "../wiring-manifest.js"; import { type AdvisorInstructionSeat } from "./advisor-instructions.js"; import { type AnnounceOnceLedger } from "./announce-once-ledger.js"; import type { Prepared } from "./contracts.js"; export interface PrepareAdvisorInput { /** borrowed-readonly — the REBOUND spec: the advisor model, the caller's tools (the reserved name), the auth hook. */ spec: Pick<TaskSpec, "advisorModel" | "tools" | "getApiKeyAndHeaders">; /** borrowed-readonly — the deployment switch as the value door screened it. */ advisorTool: "disabled" | undefined; /** borrowed-readonly — the catalog and tiers the verdict reads, the brain the advisor lane books, the notice sink. */ deps: Pick<RunnerDeps, "models" | "tiers" | "brain" | "modelFallback" | "cacheRetention" | "onNotice">; /** borrowed-readonly — the leg's resolved main model. */ model: Model; /** borrowed-mutable — the mount array (the advisor tool is mounted on it) and its mount ledger (the advisor row). */ roster: RosterBuilder; /** borrowed-readonly — the acquired session: its branch (the hold, the segment). */ session: { getBranch(): Promise<ReadonlyArray<SessionTreeEntry>>; }; /** borrowed-readonly — the once-per-session ledger: what the model was told (`arms().advisor`), and the notice's dedupe. */ onceLedger: Pick<AnnounceOnceLedger, "arms" | "oncePerSession">; /** borrowed-readonly — a leg the person reads (not a delegated child): only such a leg tells them. */ rootLeg: boolean; /** borrowed-readonly — the acquired session's id (the notice's routing key). */ sessionId: string; /** borrowed-readonly — this invocation's id (the notices' correlation key). */ runId: string | undefined; /** borrowed-readonly — the leg's usage-account door (the run body binds it before any tool call). */ sideCallBookRef: Prepared["sideCallBookRef"]; /** borrowed-readonly — reads each consultation's request against the session's main line before it goes out. */ observeSideRequest: Prepared["observeSideRequest"]; /** borrowed-readonly — the request the main lane last sent (read at each call). */ lastSentRequest: () => CompactionForkContext | undefined; /** borrowed-readonly — the leg's resolved brain-call guardrail (the value doors' answer; `undefined` = off). */ brainCallGuardrailMs: number | undefined; /** borrowed-readonly — the run's engine text reading (the instructions frame is worded in it). */ say: EngineText; } export interface PrepareAdvisorResult { /** The manifest's `advisor` fact; absent ⇔ the spec names no advisor model. */ manifest: WiringAdvisorFact | undefined; /** The leg's instruction seat; absent when there is nothing to tell and nothing told. */ instruction: AdvisorInstructionSeat | undefined; } /** The phase body — see the module header. Throws only `config.reserved_tool_name` (a caller tool named `advisor` on a leg that mounts it). */ export declare function prepareAdvisor(input: PrepareAdvisorInput): Promise<PrepareAdvisorResult>;