@sema-agent/core
Version:
Stateless, task-oriented AI agent core
26 lines (25 loc) • 1.7 kB
TypeScript
import type { Model } from "../internal/llm.js";
/** Coarse price/capability tier, declared on a model via `model.params.tier`. */
export type ModelTier = "cheap" | "standard" | "premium";
/** Declarative "pick a model by capability/price" criteria (design/11 Layer 2). */
export interface ModelCriteria {
/** Required capabilities. `vision` = accepts images; `reasoning` = supports extended thinking. */
needs?: Array<"vision" | "reasoning">;
/** Minimum usable context window (`contextTokens ?? contextWindow`). */
minContext?: number;
/** Require an exact tier — read from `model.params.tier` (`"cheap" | "standard" | "premium"`). */
tier?: ModelTier;
/** Tiebreak among the matches by total `cost` ($/Mtok input+output). Default `"cheapest"`. */
prefer?: "cheapest" | "premium";
}
/**
* Pick a model from a catalog by capability + price. Filters by `needs`/`minContext`/`tier`, then
* ranks the survivors by total list cost (`prefer: "cheapest"` default, or `"premium"` = priciest as
* a capability proxy). Returns `undefined` when nothing matches. The capability/price fields already
* live on `Model` (`input`, `reasoning`, `contextWindow`, `cost`); `tier` is opt-in via
* `model.params.tier`. This is the static version of cost-aware routing (RouteLLM is the dynamic,
* per-query north star — see design/11); compose it into `roles` via a `{ select }` RoleSpec.
*/
export declare function selectModel(models: Record<string, Model> | Model[], criteria?: ModelCriteria): Model | undefined;
/** Throwing variant of {@link selectModel}. */
export declare function selectModelOrThrow(models: Record<string, Model> | Model[], criteria?: ModelCriteria): Model;