UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

45 lines (44 loc) • 2.92 kB
import { deliverEngineNotice } from "../engine-notice.js"; import { entriesNotAppliedDetail } from "../entries-not-applied.js"; import { absentTierReading, bindingShown, roleFallbackChain, unheldRoleSeats } from "../roles.js"; import { announceDigest } from "./announce-once-ledger.js"; const MODEL_WORD_UNKNOWN_LANE = "config.entries_not_applied:model_word_unknown"; const STANDS_IN = { summarize: "the compaction summary runs on the conversation's own model", subagent: "child runs go on the parent run's model", verifier: "the verification gate runs on the main model", consolidate: "memory consolidation runs on the summarize role's model, and is refused when that supplies none", }; const TIER_DEFAULT_STANDS_IN = " (or the tier default for that role, when tiers are declared)"; export function roleDefaultedNotice(u, ids) { const shown = bindingShown(u.word); const reason = u.cause === "tier_unbound" ? "tier_unbound" : "unknown_model_ref"; const absent = reason === "tier_unbound" ? absentTierReading(u.word) : undefined; const standsIn = (STANDS_IN[u.role] ?? "its fallback chain decides") + (u.role === "summarize" && u.ownTierBound ? TIER_DEFAULT_STANDS_IN : ""); return { code: "config.entries_not_applied", message: absent !== undefined ? `The ${u.role} seat names the model tier ${shown}, and this deployment's model tiers bind ${absent.gap}, so the seat is read as an unset one: ${standsIn}. ` + `Bind a model ${absent.fix} in this deployment's model tiers, or correct the seat. Said once per conversation for this seat.` : `The ${u.role} seat names the model ${shown}, which this deployment's model catalog does not hold, so the seat is read as an unset one: ${standsIn}. ` + `Declare ${shown} in this deployment's model catalog or correct the seat. Said once per conversation for this seat.`, detail: { ...entriesNotAppliedDetail("model_word_unknown", [{ entry: u.word.length > 80 ? `${u.word.slice(0, 80)}…` : u.word, seat: u.seat, role: u.role, reason, fallback: [...roleFallbackChain(u.role)] }]), sessionId: ids.sessionId, ...(ids.runId !== undefined ? { runId: ids.runId } : {}), }, sessionId: ids.sessionId, }; } export function announceRoleSeatsDefaulted(input) { if (!input.rootLeg) return; const seen = new Set(); for (const u of [...unheldRoleSeats({}, input.deps), ...unheldRoleSeats(input.spec, input.deps)]) { const key = `${u.seat}\n${u.word}\n${u.cause}`; if (seen.has(key)) continue; seen.add(key); input.onceLedger.oncePerSession(announceDigest(MODEL_WORD_UNKNOWN_LANE, key), () => deliverEngineNotice(input.deps.onNotice, roleDefaultedNotice(u, { sessionId: input.sessionId, ...(input.runId !== undefined ? { runId: input.runId } : {}) }))); } }