@sema-agent/core
Version:
Stateless, task-oriented AI agent core
60 lines (59 loc) • 3.68 kB
TypeScript
/**
* The request media trim at the session's media-item limit for a model whose endpoint refused a request over its media blocks
* (`errorKind: "media_items_refused"`: a 400 stating "too many or oversized images").
*
* One run's seat, built by the context lane and driven by the loop (`mediaItemLimit` of its config):
* - `trim` — the lane's one request media trim (`trimRequestMedia`) at `requestMediaLimits(model, knob, limit)`, where the limit
* is the run's pending one for that model, else the session's (`seed` reads it once, at the run's first build, beside the
* cleared-results record), and keeps how many media blocks the request to that model kept;
* - `lower` — the provider refused that request: the first rung of `IMAGE_ADMISSION.request.refusalRungs` under the count it
* kept (and under the rung this run already lowered to) becomes the run's pending limit for that model, the turn's re-send
* is trimmed to it, and `true` says so; with no rung left, the pending limit is dropped and the refusal ends the turn;
* - `answered` — the turn that lowered ended (its tool results in) with a final that is not a failure: when that final is the pending limit's own
* model's (`provider` and model id alike), the limit is the session's — one engine-owned `custom` entry, at the turn's end, read
* by every later request to that model; any other answer drops the pending limit.
*
* The session's limit is the newest entry on the session's branch (one model at a time, as the reference holds one). A read
* that fails or does not read, and a write that fails, are said on `onError` (`degraded`): the run goes on with what it
* holds — no limit for a failed read, the answered limit for a failed write.
*/
import type { AgentMessage, SessionTreeEntry } from "../../internal/harness-types.js";
import { type RequestMediaLimits } from "../image-admission.js";
import { type RequestMediaTrim } from "../media-byte-cap.js";
import type { RunnerDeps } from "../types.js";
export declare const MEDIA_ITEM_LIMIT_CUSTOM_TYPE = "engine:media-item-limit";
export interface MediaItemLimitSession {
getBranch(): Promise<ReadonlyArray<SessionTreeEntry>>;
appendCustomEntry(customType: string, data?: unknown): Promise<string>;
}
/** The model a limit is held for: its `provider` and model id, as an answer's message states them (`model`). */
export interface MediaItemLimitModel {
readonly provider: string;
readonly model: string;
}
/** A limit for one model. */
export interface HeldMediaItemLimit extends MediaItemLimitModel {
readonly limit: number;
}
/** The newest record on `branch`: its limit, `undefined` when the branch holds none, `"malformed"` when the newest does not read. */
export declare function storedMediaItemLimit(branch: ReadonlyArray<SessionTreeEntry>): HeldMediaItemLimit | undefined | "malformed";
/** A model entry as the trim reads it. */
type TrimmedModel = {
readonly provider: string;
readonly id: string;
readonly contextWindow?: unknown;
readonly mediaItemLimit?: unknown;
};
/** One run's seat (see the module head). */
export interface MediaItemLimitSeat {
/** Read the session's limit, once per run (every later call is a no-op). */
seed(): Promise<void>;
trim(messages: AgentMessage[], model: TrimmedModel, knob: number | undefined): {
trim: RequestMediaTrim;
limits: RequestMediaLimits;
};
lower(): boolean;
answered(by: MediaItemLimitModel): Promise<void>;
}
export declare function createMediaItemLimitSeat(session: MediaItemLimitSession, deps: Pick<RunnerDeps, "onError">, sessionId: string): MediaItemLimitSeat;
export {};