@sema-agent/core
Version:
Stateless, task-oriented AI agent core
38 lines (37 loc) • 2.33 kB
TypeScript
import type { Model } from "../../internal/llm.js";
import { type MaybeCompactOptions } from "../auto-compaction.js";
import { type ModelPricing } from "../pricing.js";
import type { Brain, TaskSpec } from "../types.js";
import type { Stats } from "./assemble-result.js";
import type { Prepared, RunnerDepsSeat, RunState } from "./contracts.js";
export interface RunCompactionMachineryInput {
/** borrowed-readonly — the task spec: the compaction settings. */
spec: TaskSpec;
/** borrowed-readonly — the leg's prepared seat: the model, the prompt overhead, the usage governance and the session id. */
prepared: Prepared;
/** borrowed-mutable — the run's mutable state: `telemetry.unpricedSpend` is set when a summarizer model is unpriced;
* the budget ceiling and the telemetry are read. */
rs: RunState;
/** borrowed-mutable — the run's usage counters: every accounted summary call adds to them (compaction spend
* tracked separately too). */
stats: Stats;
/** borrowed-readonly — the telemetry lane's price-table door, consulted for every summarizer table adopted. */
noteUnevaluablePriceTable: (p: ModelPricing) => void;
/** borrowed-readonly — the Runner's deployment deps, read LIVE (`brain`, `pricing`, `onError`). */
runner: RunnerDepsSeat;
}
export interface RunCompactionMachineryResult {
/** The accounted compaction brain — `complete` always provided, usage recorded inline. */
compactionBrain: Brain;
/** Whether ROUTINE turn-boundary compaction runs for this task, asked AT THE BOUNDARY. The request's own
* `compaction` is fixed for the leg, but the deployment's per-model overlay is a live seat — an operator
* who turns routine compaction off for a model reaches the legs already on it. */
withinTaskCompaction: () => boolean;
/** §17.4: the consecutive-failure circuit breaker shared by every compaction lane of the run. */
compactionBreaker: {
failures: number;
};
/** The window-safety wiring (per call — a mid-task degrade moves the fallback target). */
windowSafetyOptions: (mainModel: Model) => Pick<MaybeCompactOptions, "fallbackBudget" | "onWindowSafety">;
}
export declare function runCompactionMachinery(input: RunCompactionMachineryInput): RunCompactionMachineryResult;