@sema-agent/core
Version:
Stateless, task-oriented AI agent core
53 lines (52 loc) • 4.06 kB
TypeScript
/**
* The cause words of a resource park — a leaf (it imports nothing), so that every reader of the words can ask the one list without
* pulling the checkpoint store's module graph in: the park card a background agent's state carries reads it from a module the
* checkpoint store sits above. `checkpoint-store.ts`, where the gate that carries the word is declared, re-exports all of it.
*/
/**
* Why a `resource_limit` suspend was minted. design/164 split the single `budget` member: a token
* window and a $ window are different allowances with different owners, and a scheduler reading a
* checkpoint inbox to decide "grant more of what?" could not tell them apart. The reasons match the
* terminal codes the non-suspending tier reports (`limits.max_*_exceeded`), so one vocabulary covers
* both tiers.
*
* **Consumers pinning the old closed set**: `"budget"` is gone — a switch on it now falls through.
*
* Three members are a DIFFERENT CLASS from the task axes above — the EXTERNAL causes ({@link PlatformLimitReason}):
* `"preempt"` (a scheduler's yield, `TaskSpec.preemptSignal` — not a limit, its resume continues the work),
* `"usage_window"` (a deployment-level usage-governance window is exhausted) and `"env_lifetime"` (the
* execution environment's platform lifetime is about to expire). The task did not choose them and cannot
* avoid them by asking for less, so they suspend on the INFRASTRUCTURE eligibility alone (checkpoint store +
* non-volatile offload + remote/no owned env), without the `TaskSpec.resourceSuspend` opt-in the task axes
* require. When several causes land on one turn boundary the attribution order is
* `preempt > usage_window > env_lifetime > budget_tokens > budget_cost > turns > walltime`
* (external causes above self-chosen allowances; an explicit scheduler decision above an inferred one; a
* window above a dying environment because only the window carries a wait the caller can act on).
* What each external cause falls back to when the suspend cannot be written differs, and is the turn
* boundary's one table: `preempt` continues the run and says so once (a yield is a request, not a stop),
* `usage_window` / `env_lifetime` stop it loudly with their own terminal codes.
*
* **Consumers pinning the closed set again**: a `switch` that was exhaustive over the five 5.x members
* now falls through on `env_lifetime` / `usage_window`.
*
* The type is derived from the frozen list {@link RESOURCE_LIMIT_REASONS}; every reader that asks "is this word a cause"
* asks {@link isResourceLimitReason}.
*/
export declare const RESOURCE_LIMIT_REASONS: readonly ["budget_tokens", "budget_cost", "walltime", "turns", "preempt", "env_lifetime", "usage_window"];
export type ResourceLimitReason = (typeof RESOURCE_LIMIT_REASONS)[number];
/** Membership test for {@link ResourceLimitReason}. */
export declare function isResourceLimitReason(v: unknown): v is ResourceLimitReason;
/**
* design/164 件四/件五 — the EXTERNAL subset of {@link ResourceLimitReason}: causes that come from the
* platform or the operator rather than from the task's own declared allowances. The frozen list
* {@link PLATFORM_LIMIT_REASONS} names which words of {@link RESOURCE_LIMIT_REASONS} are external, in that list's order;
* the compiler holds it to that list's words, so the two can never drift into disagreeing about what "external" means,
* and a seam that may only be reached by an external cause (the infrastructure-only suspend lane) cannot be handed a
* task-axis reason by mistake. The type is derived from it.
*
* **Consumers pinning the closed set**: `"preempt"` joined (it used to suspend through the task-axis lane
* behind the `resourceSuspend` opt-in). It never yields a platform terminal code — its fallback is to keep
* running — so an exhaustive `switch` adds an arm that produces no stop.
*/
export declare const PLATFORM_LIMIT_REASONS: readonly ["preempt", "env_lifetime", "usage_window"];
export type PlatformLimitReason = (typeof PLATFORM_LIMIT_REASONS)[number];