feat(ultra): add model tiers
05eb805a840c56a72949dfb8199e4eabc1ae4fe3
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: e0994e7c3ca9
bugabingas pi extensions
05eb805a840c56a72949dfb8199e4eabc1ae4fe3
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+189 / −22 text lines
+24 / −7 text lines
| Key | Default | Meaning || -------------------------- | -------- | ----------------------------------------------- || `ultra.enabled` | `true` | When false, the tool + command refuse to run. || `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. || `ultra.maxRetries` | `2` | Schema-validation retries per step. || `ultra.defaultTimeoutMs` | `180000` | Per-step timeout when a step omits `timeoutMs`. || `ultra.subagentExtensions` | `"all"` | Load host extensions into sub-agents, or not. || Key | Default | Meaning || -------------------------- | -------- | -------------------------------------------------- || `ultra.enabled` | `true` | When false, the tool + command refuse to run. || `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. || `ultra.maxRetries` | `2` | Schema-validation retries per step. || `ultra.defaultTimeoutMs` | `180000` | Per-step timeout when a step omits `timeoutMs`. || `ultra.subagentExtensions` | `"all"` | Load host extensions into sub-agents, or not. || `ultra.modelTiers` | `{}` | Optional `small` / `medium` / `big` model aliases. |`ultra.modelTiers` maps workflow step `model` values of `small`, `medium`, or `big` to concrete model refs.Unset tiers fall back to the session model.A tier value may end with a thinking suffix (`:off`, `:minimal`, `:low`, `:medium`, `:high`, `:xhigh`), used when the step omits `thinkingLevel`.```json{ "ultra": { "modelTiers": { "small": "openai/gpt-5-mini:low", "medium": "anthropic/claude-sonnet-4:medium", "big": "openai/gpt-5.1:xhigh" } }}```+60 / −0 text lines
it("resolves configured model tier aliases before completeFn auth", async () => { const completeFn = vi.fn( async (): Promise<CompleteResponse> => ({ text: '{ "verdict": "ok" }' }), ); const resolveModel = vi.fn((m?: string) => ({ id: m ?? "host" })); const drivers = makeDrivers({ completeFn, resolveModel }); await runStep( { ...toollessStep, model: "small" }, makeCtx(), drivers, baseOpts({ modelTiers: { small: "openai/gpt-5-mini:low" } }), ); expect(resolveModel).toHaveBeenCalledWith("openai/gpt-5-mini"); }); it("unconfigured model tiers fall back to the session model", async () => { const completeFn = vi.fn( async (): Promise<CompleteResponse> => ({ text: '{ "verdict": "ok" }' }), ); const resolveModel = vi.fn((m?: string) => ({ id: m ?? "host" })); const drivers = makeDrivers({ completeFn, resolveModel }); await runStep( { ...toollessStep, model: "small" }, makeCtx(), drivers, baseOpts(), ); expect(resolveModel).toHaveBeenCalledWith(undefined); }); it("applies a tier thinking suffix to tool-using sessions unless the step overrides it", async () => { const harness = makeSessionHarness({ drive: happyDrive({ verdict: "tiered" }), }); const drivers = makeDrivers({ sessionFactory: harness.factory }); await runStep( { ...toolStep, model: "small" }, makeCtx(), drivers, baseOpts({ modelTiers: { small: "openai/gpt-5-mini:low" } }), ); expect(harness.captured.args?.thinkingLevel).toBe("low"); const overrideHarness = makeSessionHarness({ drive: happyDrive({ verdict: "override" }), }); await runStep( { ...toolStep, model: "small", thinkingLevel: "high" }, makeCtx(), makeDrivers({ sessionFactory: overrideHarness.factory }), baseOpts({ modelTiers: { small: "openai/gpt-5-mini:low" } }), ); expect(overrideHarness.captured.args?.thinkingLevel).toBe("high"); });+27 / −2 text lines
+1 / −0 text lines
+46 / −5 text lines
import type { ModelTiers } from "./settings.ts";function isModelTierName(value: string): value is keyof ModelTiers { return value === "small" || value === "medium" || value === "big";}function splitTierSpec(spec: string): { model: string; thinkingLevel?: ThinkingLevel;} { const match = spec.match(/^(.*):(off|minimal|low|medium|high|xhigh)$/); if (!match) return { model: spec }; return { model: match[1], thinkingLevel: match[2] as ThinkingLevel };}function resolveModelTier(step: Step, tiers: ModelTiers | undefined): Step { if (!step.model || !isModelTierName(step.model)) return step; const tier = tiers?.[step.model]; if (!tier) { const { model: _model, ...withoutModel } = step; return withoutModel; } const resolved = splitTierSpec(tier); return { ...step, model: resolved.model, thinkingLevel: step.thinkingLevel ?? resolved.thinkingLevel, };} const schemaObj = resolveStepSchema(step, opts);+19 / −0 text lines
modelTiers: {},function pickModelTiers(raw: unknown): ModelTiers | undefined { if (!isPlainObject(raw)) return undefined; const out: ModelTiers = {}; for (const name of ["small", "medium", "big"] as const) { const value = raw[name]; if (typeof value === "string") out[name] = value; } return out;} modelTiers: isPlainObject(p.modelTiers) ? p.modelTiers : into.modelTiers,+12 / −8 text lines
| Field | Required | Type | Meaning || --------------- | -------- | --------------------- | ----------------------------------------------------------------- || `prompt` | yes | string | The agent instruction. Interpolates `{...}` tokens (see below). || `tools` | no | string[] | Tool allowlist. Omit for a tool-less completion (pure reasoning). || `model` | no | string | `provider/id` override; defaults to the session model. || `thinkingLevel` | no | off…xhigh | Reasoning budget for this step. || `schema` | no | string \| JSON Schema | A `schemas` name, or an inline schema. Forces structured output. || `timeoutMs` | no | number | Per-agent timeout. || Field | Required | Type | Meaning || --------------- | -------- | --------------------- | ------------------------------------------------------------------------------------------------- || `prompt` | yes | string | The agent instruction. Interpolates `{...}` tokens (see below). || `tools` | no | string[] | Tool allowlist. Omit for a tool-less completion (pure reasoning). || `model` | no | string | `provider/id` override, or configured tier `small`/`medium`/`big`; defaults to the session model. || `thinkingLevel` | no | off…xhigh | Reasoning budget for this step. || `schema` | no | string \| JSON Schema | A `schemas` name, or an inline schema. Forces structured output. || `timeoutMs` | no | number | Per-agent timeout. |Configured model tiers live in Pi settings under `ultra.modelTiers`.If a step sets `model` to `small`, `medium`, or `big`, ultra resolves it through that map; an unset tier falls back to the session model.Tier values may include a thinking suffix like `openai/gpt-5-mini:low`, used only when the step omits `thinkingLevel`.