agentcompass 0.1.3: :minimal and :ultra are efforts; ultra reads as the model's Max, minimal sits below its Low (#750)
agentcompass 0.1.3. `:minimal` and `:ultra` are read as efforts. `ultra` maps to the model's Max, or to the policy table's max when the model has no curve. `minimal` sits below the model's Low, and is clamped by a step floor and the burn scale. `none`/`off` stay in the policy. Quota is scaled through `burnScale` rather than the raw tables. A model with no curve (glm-5.3) uses the policy table's Low. A request that nothing routes now falls back through `fallbackToBestExcluded`, in both the middleware and the hooks. The fallback's tiers are: below the floor only, then seeing models, then the rest. The README (en/zh) notes that the fallback can override the visual, unhealthy, context and quota constraints.
Reviewed head: ff614f0316ab5b1a07bcc68afd11b69bb6e892d3 (merge-base 42331f64 = origin/main).
Run on mote (mote-run, HOME=$(mktemp -d)):
- packages/agentcompass `node --test`: 44 pass. `bun test`: 44 pass.
- repo `bun test`: 6188 pass, 20 skip, 0 fail. `bun scripts/check.mjs`: exit 0.
- PR CI (test, on-npm): green on ff614f0.
Broken by hand. All 16 went red:
- A-H turned 9.13 red: ability-only fallback, no floor-only tier, no seeing tier, onlyBelowFloor from the floor alone, tier order flipped, no fallback in middleware, no fallback in hooks, old middleware retry condition.
- I (quota from the raw tables) and J (below-Low scaling from the model's own Low) turned 9.12 red.
- K (no ultra to own max) turned 9.10 and 9.12 red.
- L (no ultra to policy max) turned 9.11 and 9.12 red.
- M (no step floor) and N (no burn clamp) turned 9.11 red.
- O (old EFFORT_ORDER) turned 9.10, 9.11 and 9.13 red.
- P (none/off out of the policy) turned 8.12, 9.11 and 9.13 red.
Version 0.1.2 to 0.1.3 sits on main's 0.1.2 and on dist's latest (tgz 0.1.2). The package is not on npm, so it ships through the dist branch.
Not tried: a real magpie gateway routing through 0.1.3.
This commit is contained in:
@@ -46,6 +46,8 @@ magpie plugin options <plugin-spec> '{"candidateModels":["claude-opus-4-6","clau
|
||||
|
||||
- Requests to `agentcompass` or `agentcompass/*` rewrite `body.model` to `<targetModel>:<targetEffort>` (which Magpie's gateway splits natively) and set protocol-specific effort fields (`reasoning_effort`, `reasoning.effort`, `output_config.effort`).
|
||||
- If a virtual model (`agentcompass` / `agentcompass/*`) is requested without `candidateModels` or `defaultModel`, the middleware rejects the call with HTTP 400 (`agentcompass: set candidateModels in the plugin's options`) rather than guessing models.
|
||||
- Efforts written in a candidate face the task's ability floor like any other: `:minimal`, `:none` and `:off` count as less capable than `:low`, so harder tasks exclude them.
|
||||
- The gateway never leaves a request unrouted. If no candidate passes, it retries without the temporary unhealthy, context and quota constraints. If none passes then, it falls back to an excluded candidate and marks the decision `fallback`: first one that misses only the ability floor, then one that can read the request's images, with ability breaking ties. So the fallback can override the visual, unhealthy, context and quota constraints, but it only ever picks from your candidate list.
|
||||
- If `routeAllModels: true` is set without `candidateModels`, concrete model names are kept as-is and only the reasoning effort is injected.
|
||||
|
||||
### 3. Account-pool seat strategy (`routings`)
|
||||
@@ -191,6 +193,8 @@ magpie plugin options <plugin-spec> '{"candidateModels":["claude-opus-4-6","clau
|
||||
|
||||
- 请求虚拟模型 `agentcompass` / `agentcompass/*` 时,中间件将 `body.model` 改写为 `<targetModel>:<targetEffort>`,并按协议注入思考档位字段(`reasoning_effort`、`reasoning.effort`、`output_config.effort`)。
|
||||
- 未配置 `candidateModels` 或 `defaultModel` 时请求虚拟模型会返回 HTTP 400(`agentcompass: set candidateModels in the plugin's options`),不猜测模型列表。
|
||||
- 候选里写明的思考档位同样要过任务的能力底线:`:minimal`、`:none`、`:off` 按低于 `:low` 的能力计算,较难的任务会把它们排除。
|
||||
- 网关不会让请求落空。没有候选通过时,先去掉临时的不健康、上下文和配额约束重试;仍无候选通过时,从被排除的候选中回退并在路由决策里标记 `fallback`:优先只差能力底线的候选,其次能读取请求中图片的候选,同级按能力高低决定。因此回退可能越过视觉、不健康、上下文和配额约束,但只会从你的候选列表中选择。
|
||||
- 开启 `routeAllModels: true` 且未配置候选列表时,具体模型名保持不变,仅自动注入思考档位。
|
||||
|
||||
#### 3. 账号池席位排序(`routings`)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/gateway-agentcompass",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "Intent, multi-dimensional capability, Model DNA, subscription quota opportunity-cost, and session-affinity routing plugin for Magpie, powered by AgentCompass.",
|
||||
"type": "module",
|
||||
"main": "./src/index.js",
|
||||
|
||||
@@ -25,7 +25,10 @@ import {
|
||||
resolveModelSpec,
|
||||
} from "./catalog.js";
|
||||
import { inferTaskProfile, validateProfile } from "./profiler-core.js";
|
||||
import { evaluateModelQuota, normalizeQuotaSnapshot } from "./quota.js";
|
||||
// effortValue and burnScale live in quota.js so its opportunity cost reads the same burn scale as the allocator.
|
||||
import { burnScale, effortValue, evaluateModelQuota, normalizeQuotaSnapshot } from "./quota.js";
|
||||
|
||||
export { burnScale, effortValue };
|
||||
|
||||
export const EFFORT_SCALED_CAPABILITIES = [
|
||||
"reasoning",
|
||||
@@ -74,13 +77,6 @@ export function profileKind(profile, policy = DEFAULT_SCORING_POLICY) {
|
||||
return policy?.profile?.kind_by_style?.[profile.interaction_style] || "other_or_mixed";
|
||||
}
|
||||
|
||||
export function effortValue(policy, curves, name, effort, fallback) {
|
||||
const own = curves?.[name] || {};
|
||||
if (effort in own) return own[effort];
|
||||
const policyTable = policy?.[`effort_${name}`] || {};
|
||||
return effort in policyTable ? policyTable[effort] : fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* The model's effective tier at one effort level (`allocator.py:effort_ability`).
|
||||
*/
|
||||
@@ -93,16 +89,6 @@ export function effortAbility(policy, curves, info, effort = "high") {
|
||||
return tier + effortValue(policy, curves, "ability", effort, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative burn scale of `effort` compared to `high` (`allocator.py:burn_scale`).
|
||||
*/
|
||||
export function burnScale(policy, curves, effort = "high") {
|
||||
const mult = curves?.burn_mult || {};
|
||||
if (effort in mult) return Number(mult[effort]);
|
||||
const ref = effortValue(policy, curves, "burn", "high", 0.7);
|
||||
return effortValue(policy, curves, "burn", effort, ref) / (ref || 1.0);
|
||||
}
|
||||
|
||||
export function capabilityVector(info) {
|
||||
const raw = info?.capabilities || {};
|
||||
const legacyVisual = typeof info?.visual === "number" ? info.visual : 0.0;
|
||||
@@ -402,7 +388,8 @@ export function evaluateCandidate(candidate, taskCtx, catalog = {}) {
|
||||
const curves = curvesTable[canonical] || {};
|
||||
const excluded = [];
|
||||
|
||||
if (taskCtx.needs_visual && !info.visual) {
|
||||
const cannotSeeInput = Boolean(taskCtx.needs_visual && !info.visual);
|
||||
if (cannotSeeInput) {
|
||||
excluded.push("task needs visual input");
|
||||
}
|
||||
if (taskCtx.unhealthy_models && taskCtx.unhealthy_models.has(canonical)) {
|
||||
@@ -627,6 +614,8 @@ export function evaluateCandidate(candidate, taskCtx, catalog = {}) {
|
||||
fast: Boolean(quotaEval?.fast),
|
||||
excluded,
|
||||
eligible: excluded.length === 0,
|
||||
cannotSeeInput,
|
||||
onlyBelowFloor: excluded.length === 1 && ability < gate,
|
||||
score: excluded.length === 0 ? totalScore : null,
|
||||
quota: quotaEval
|
||||
? {
|
||||
@@ -830,14 +819,34 @@ export function rankCandidates(profileInput, options = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function fallbackTier(candidate) {
|
||||
if (candidate.onlyBelowFloor) return 0;
|
||||
return candidate.cannotSeeInput ? 2 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience entry point: takes a raw request or task object + options and returns the winning route decision.
|
||||
*
|
||||
* `fallbackToBestExcluded` is for gateways. AgentCompass may leave a task unrouted when no candidate clears its
|
||||
* floor, but a gateway that does so forwards the virtual model name upstream and the request fails. With the
|
||||
* option, an excluded candidate is chosen instead and the decision carries `fallback`: one that only misses the
|
||||
* floor, else one that can see the request's images, with ability breaking ties. Falling short of a floor still
|
||||
* answers the request; a model that can't see its images can't.
|
||||
*/
|
||||
export function selectBestRoute(taskOrProfile, options = {}) {
|
||||
const result = rankCandidates(taskOrProfile, options);
|
||||
const top = result.selected;
|
||||
let top = result.selected;
|
||||
let fallback = null;
|
||||
if (!top && options.fallbackToBestExcluded && result.allCandidates.length > 0) {
|
||||
top = result.allCandidates.reduce((best, c) => {
|
||||
const tier = fallbackTier(c) - fallbackTier(best);
|
||||
return tier < 0 || (tier === 0 && c.components.ability_value > best.components.ability_value) ? c : best;
|
||||
});
|
||||
fallback = { excluded: top.excluded };
|
||||
}
|
||||
return {
|
||||
ok: Boolean(top),
|
||||
fallback,
|
||||
targetModel: top ? top.model : null,
|
||||
canonicalModel: top ? top.canonicalModel : null,
|
||||
targetEffort: top ? top.effort : "high",
|
||||
|
||||
@@ -39,7 +39,7 @@ export const DEPTH_BY_DIFFICULTY = {
|
||||
frontier: 4,
|
||||
};
|
||||
|
||||
export const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max", "ultra"];
|
||||
export const EFFORT_ORDER = ["none", "off", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"];
|
||||
|
||||
export const HARD_BY_DEFAULT = [
|
||||
"debug_review",
|
||||
@@ -1410,6 +1410,9 @@ export const DEFAULT_SCORING_POLICY = {
|
||||
frontier: 0.1,
|
||||
},
|
||||
effort_ability: {
|
||||
none: -1.1,
|
||||
off: -1.1,
|
||||
minimal: -1.0,
|
||||
low: -0.54,
|
||||
medium: -0.2,
|
||||
high: 0.0,
|
||||
|
||||
@@ -298,13 +298,14 @@ export async function onRequest(body, ctx = {}) {
|
||||
},
|
||||
});
|
||||
|
||||
// Graceful fallback if all candidates were filtered out by temporary unhealthy/context/quota constraints
|
||||
if (!decision.ok && (unhealthyModels.length > 0 || minContextTokens > 0 || liveQuotas)) {
|
||||
// Without the temporary unhealthy/context/quota constraints, and never unrouted: see selectBestRoute.
|
||||
if (!decision.ok) {
|
||||
decision = selectBestRoute(profile, {
|
||||
objective: facts.objective,
|
||||
candidateModels,
|
||||
catalog: options.catalog,
|
||||
now,
|
||||
fallbackToBestExcluded: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -357,6 +358,7 @@ export async function onRequest(body, ctx = {}) {
|
||||
hasExplicitCandidates,
|
||||
selectedAccount: decision.selectedAccount || null,
|
||||
quota: decision.quota || null,
|
||||
fallback: decision.fallback || null,
|
||||
workKind: decision.workKind,
|
||||
difficulty: decision.difficulty,
|
||||
requiredAbility: decision.requiredAbility,
|
||||
|
||||
@@ -358,12 +358,14 @@ export function onRequest(body, ctx = {}) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!decision.ok && (unhealthyModels.length > 0 || minContextTokens > 0 || options.quotas)) {
|
||||
if (!decision.ok) {
|
||||
// Without the temporary unhealthy/context/quota constraints, and never unrouted: see selectBestRoute.
|
||||
decision = selectBestRoute(profile, {
|
||||
objective: facts.objective,
|
||||
candidateModels,
|
||||
catalog: options.catalog,
|
||||
now,
|
||||
fallbackToBestExcluded: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,43 @@ export function round4(val) {
|
||||
return Math.round(val * 10000) / 10000;
|
||||
}
|
||||
|
||||
/**
|
||||
* One effort's ability delta or burn (`allocator.py:effort_value`), plus two plugin-side fallbacks AgentCompass
|
||||
* doesn't have: `ultra` without its own calibration reads as the model's Max, and `none`/`off`/`minimal` sit
|
||||
* below the model's own Low rather than at the policy table's generic value. Upstream scores both at High.
|
||||
*/
|
||||
export function effortValue(policy, curves, name, effort, fallback) {
|
||||
const own = curves?.[name] || {};
|
||||
if (effort in own) return own[effort];
|
||||
if (effort === "ultra" && "max" in own) return own.max;
|
||||
const policyTable = policy?.[`effort_${name}`] || {};
|
||||
// Below Low, scale from the model's own Low, else the policy table's: a model without a curve still has a Low.
|
||||
const low = "low" in own ? own.low : policyTable.low;
|
||||
if ((effort === "minimal" || effort === "none" || effort === "off") && low !== undefined) {
|
||||
if (name === "ability") {
|
||||
const delta = (policyTable[effort] ?? -1.0) - (policyTable.low ?? -0.54);
|
||||
return low + Math.min(delta, -0.2);
|
||||
}
|
||||
if (name === "burn") {
|
||||
const ratio = (policyTable[effort] ?? 0.12) / (policyTable.low || 0.2);
|
||||
return round4(low * Math.min(ratio, 0.75));
|
||||
}
|
||||
}
|
||||
if (effort in policyTable) return policyTable[effort];
|
||||
if (effort === "ultra" && "max" in policyTable) return policyTable.max;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative burn scale of `effort` compared to `high` (`allocator.py:burn_scale`).
|
||||
*/
|
||||
export function burnScale(policy, curves, effort = "high") {
|
||||
const mult = curves?.burn_mult || {};
|
||||
if (effort in mult) return Number(mult[effort]);
|
||||
const ref = effortValue(policy, curves, "burn", "high", 0.7);
|
||||
return effortValue(policy, curves, "burn", effort, ref) / (ref || 1.0);
|
||||
}
|
||||
|
||||
export function round3(val) {
|
||||
return Math.round(val * 1000) / 1000;
|
||||
}
|
||||
@@ -905,9 +942,7 @@ export function evaluateModelQuota(
|
||||
|
||||
const { canonical, spec: info } = resolveModelSpec(rawModel, models, aliases);
|
||||
const curves = curvesTable[canonical] || {};
|
||||
const refBurn = curves?.burn?.high ?? policy?.effort_burn?.high ?? 0.7;
|
||||
const effBurn = curves?.burn?.[effort] ?? policy?.effort_burn?.[effort] ?? refBurn;
|
||||
const effortScale = refBurn > 0 ? effBurn / refBurn : 1.0;
|
||||
const effortScale = burnScale(policy, curves, effort); // as `allocator.py` does: one scale with the allocator
|
||||
|
||||
const taskHours = Number(
|
||||
taskCtx.hours ??
|
||||
|
||||
@@ -5,8 +5,8 @@ import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { namedRoute, rankCandidates, selectBestRoute } from "../src/allocator.js";
|
||||
import { DEFAULT_SCORING_POLICY, EFFORT_CURVES } from "../src/catalog.js";
|
||||
import { burnScale, effortValue, namedRoute, rankCandidates, selectBestRoute } from "../src/allocator.js";
|
||||
import { CANONICAL_ROUTES, DEFAULT_SCORING_POLICY, EFFORT_CURVES } from "../src/catalog.js";
|
||||
import {
|
||||
CACHE_COLD_MS,
|
||||
CHATGPT_CODEX_COLD_MS,
|
||||
@@ -1775,8 +1775,10 @@ test("8.12 All 13 effort curves and `effort_ability` / `effort_burn` equal Agent
|
||||
assert.deepEqual(EFFORT_CURVES[model].ability, curve.ability, `${model} ability`);
|
||||
assert.deepEqual(EFFORT_CURVES[model].burn, curve.burn, `${model} burn`);
|
||||
}
|
||||
// scoring.effort_ability / scoring.effort_burn
|
||||
assert.deepEqual(DEFAULT_SCORING_POLICY.effort_ability, { low: -0.54, medium: -0.2, high: 0, xhigh: 0.15, max: 0.3 });
|
||||
// scoring.effort_ability / scoring.effort_burn: upstream's low..max; none/off/minimal are the plugin's own rows (0.1.3)
|
||||
const { none, off, minimal, ...upstreamAbility } = DEFAULT_SCORING_POLICY.effort_ability;
|
||||
assert.deepEqual(upstreamAbility, { low: -0.54, medium: -0.2, high: 0, xhigh: 0.15, max: 0.3 });
|
||||
assert.deepEqual({ none, off, minimal }, { none: -1.1, off: -1.1, minimal: -1.0 });
|
||||
assert.deepEqual(DEFAULT_SCORING_POLICY.effort_burn, { low: 0.2, medium: 0.4, high: 0.7, xhigh: 1.0, max: 1.3 });
|
||||
});
|
||||
|
||||
@@ -2302,3 +2304,205 @@ test("9.9 PR #670 Round 2 & 3 Guard: Single-pass bounded work (`scannedChars`, `
|
||||
|
||||
|
||||
|
||||
|
||||
test("9.10 Effort fallback (plugin-side, not in AgentCompass): `:minimal` and `:ultra` parse as efforts, `ultra` reads as the model's Max and `minimal` sits below its Low", () => {
|
||||
const profile = {
|
||||
work_kind: "general_implementation",
|
||||
reasoning_depth: 1,
|
||||
code_complexity: 1,
|
||||
context_scale: 2,
|
||||
divergence: 1,
|
||||
hallucination_risk: 2,
|
||||
error_cost: 1,
|
||||
needs_visual: false,
|
||||
needs_gui: false,
|
||||
local_only: true,
|
||||
interaction_style: "engineering",
|
||||
};
|
||||
const rank = (candidateModels, options = {}) => rankCandidates(profile, { candidateModels, ...options });
|
||||
const policy = DEFAULT_SCORING_POLICY;
|
||||
|
||||
// Parsing: each suffix is one candidate at that effort, not the model's whole effort list
|
||||
assert.deepEqual(
|
||||
rank(["gpt-6-astra:minimal", "gpt-6-astra:ultra"]).allCandidates.map((c) => c.id).sort(),
|
||||
["gpt-6-astra:minimal", "gpt-6-astra:ultra"],
|
||||
);
|
||||
|
||||
// Scoring on a model's own curve: ultra is its Max; minimal is its Low less the policy's Low->minimal step
|
||||
// (at least 0.2), and burns at most 0.75 of its Low
|
||||
const astra = Object.fromEntries(
|
||||
rank(["gpt-6-astra:low", "gpt-6-astra:max", "gpt-6-astra:minimal", "gpt-6-astra:ultra"]).allCandidates.map((c) => [
|
||||
c.effort,
|
||||
c.components.ability_value,
|
||||
]),
|
||||
);
|
||||
assert.equal(astra.ultra, astra.max);
|
||||
const step = Math.min(policy.effort_ability.minimal - policy.effort_ability.low, -0.2);
|
||||
assert.ok(Math.abs(astra.minimal - (astra.low + step)) < 0.001, `minimal ${astra.minimal}, low ${astra.low}`);
|
||||
const curve = { burn: { low: 0.3, high: 0.7, max: 1.4 } };
|
||||
assert.equal(burnScale(policy, curve, "ultra"), burnScale(policy, curve, "max"));
|
||||
assert.ok(effortValue(policy, curve, "burn", "minimal", 0.7) <= 0.3 * 0.75);
|
||||
|
||||
// A model whose curve has no Low row takes the policy table's minimal step, not High's 0
|
||||
const deepseek = Object.fromEntries(
|
||||
rank(["deepseek-v4.1-flash-free:minimal", "deepseek-v4.1-flash-free:high"]).allCandidates.map((c) => [
|
||||
c.effort,
|
||||
c.components.ability_value,
|
||||
]),
|
||||
);
|
||||
assert.ok(Math.abs(deepseek.minimal - (deepseek.high + policy.effort_ability.minimal)) < 0.001);
|
||||
|
||||
// Continuity: on a warm cache, minimal after low is a downgrade and keeps only a quarter of the continuity bonus
|
||||
const held = rank(["gpt-6-astra:low", "gpt-6-astra:minimal"], {
|
||||
previousModel: "gpt-6-astra",
|
||||
previousEffort: "low",
|
||||
cacheWarm: true,
|
||||
});
|
||||
const cont = Object.fromEntries(held.allCandidates.map((c) => [c.effort, c.components.continuity]));
|
||||
assert.equal(cont.low, 0.25);
|
||||
assert.equal(cont.minimal, 0.0625);
|
||||
});
|
||||
|
||||
test("9.11 Effort fallback branches the default policy can't reach: policy Max for `ultra`, the 0.2 step floor, the 0.75 burn clamp, none/off", () => {
|
||||
const profile = {
|
||||
work_kind: "general_implementation",
|
||||
reasoning_depth: 1,
|
||||
code_complexity: 1,
|
||||
context_scale: 2,
|
||||
divergence: 1,
|
||||
hallucination_risk: 2,
|
||||
error_cost: 1,
|
||||
needs_visual: false,
|
||||
needs_gui: false,
|
||||
local_only: true,
|
||||
interaction_style: "engineering",
|
||||
};
|
||||
const policy = DEFAULT_SCORING_POLICY;
|
||||
const round = (value) => Math.round(value * 1e4) / 1e4;
|
||||
const abilities = (candidateModels) =>
|
||||
Object.fromEntries(rankCandidates(profile, { candidateModels }).allCandidates.map((c) => [c.effort, c.components.ability_value]));
|
||||
|
||||
// ultra on a model with no curve of its own reads as the policy's Max
|
||||
assert.equal(EFFORT_CURVES["glm-5.3"], undefined);
|
||||
const glm = abilities(["glm-5.3:high", "glm-5.3:max", "glm-5.3:ultra"]);
|
||||
assert.equal(glm.ultra, glm.max);
|
||||
assert.ok(Math.abs(glm.ultra - (glm.high + policy.effort_ability.max)) < 0.001, `ultra ${glm.ultra}, high ${glm.high}`);
|
||||
assert.equal(effortValue(policy, undefined, "ability", "ultra", 0), policy.effort_ability.max);
|
||||
assert.equal(effortValue(policy, undefined, "burn", "ultra", 0.7), policy.effort_burn.max);
|
||||
|
||||
// Step floor: a policy whose Low->minimal step is smaller than 0.2 still puts minimal 0.2 below the model's Low
|
||||
const shallow = { ...policy, effort_ability: { ...policy.effort_ability, low: -0.54, minimal: -0.6 } };
|
||||
assert.equal(round(effortValue(shallow, { ability: { low: -0.5, high: 0 } }, "ability", "minimal", 0)), -0.7);
|
||||
// ...and a deeper step is used as given
|
||||
const deep = { ...policy, effort_ability: { ...policy.effort_ability, low: -0.54, minimal: -1.0 } };
|
||||
assert.equal(round(effortValue(deep, { ability: { low: -0.5, high: 0 } }, "ability", "minimal", 0)), -0.96);
|
||||
|
||||
// Burn clamp: a policy with effort_burn.minimal close to Low still burns at most 0.75 of the model's Low
|
||||
const curve = { burn: { low: 0.4, high: 0.7 } };
|
||||
const nearLow = { ...policy, effort_burn: { ...policy.effort_burn, low: 0.2, minimal: 0.19 } };
|
||||
assert.equal(effortValue(nearLow, curve, "burn", "minimal", 0.7), 0.3);
|
||||
const cheap = { ...policy, effort_burn: { ...policy.effort_burn, low: 0.2, minimal: 0.1 } };
|
||||
assert.equal(effortValue(cheap, curve, "burn", "minimal", 0.7), 0.2);
|
||||
|
||||
// none/off: parsed as efforts and scored from their own policy rows (below minimal), on and off a model's curve
|
||||
const astra = abilities(["gpt-6-astra:none", "gpt-6-astra:off", "gpt-6-astra:minimal", "gpt-6-astra:low"]);
|
||||
assert.deepEqual(Object.keys(astra).sort(), ["low", "minimal", "none", "off"]);
|
||||
const lowToNone = Math.min(policy.effort_ability.none - policy.effort_ability.low, -0.2);
|
||||
assert.ok(Math.abs(astra.none - (astra.low + lowToNone)) < 0.001, `none ${astra.none}, low ${astra.low}`);
|
||||
assert.equal(astra.off, astra.none);
|
||||
assert.ok(astra.none < astra.minimal, `none ${astra.none} below minimal ${astra.minimal}`);
|
||||
const glmNone = abilities(["glm-5.3:none", "glm-5.3:off", "glm-5.3:high"]);
|
||||
assert.ok(Math.abs(glmNone.none - (glmNone.high + policy.effort_ability.none)) < 0.001);
|
||||
assert.ok(Math.abs(glmNone.off - (glmNone.high + policy.effort_ability.off)) < 0.001);
|
||||
});
|
||||
|
||||
test("9.12 Quota opportunity cost reads the allocator's burn scale: `:ultra` costs what `:max` costs, `:minimal`/`none`/`off` cost less than `:low`", () => {
|
||||
const t0 = Date.parse("2026-11-05T00:00:00Z");
|
||||
const subscription = (key) => ({
|
||||
[key]: {
|
||||
kind: "subscription",
|
||||
quota: { windows: [{ name: "7d", used: 60, remaining: 40, resetsAt: new Date(t0 + 120 * 3600 * 1000).toISOString() }] },
|
||||
},
|
||||
});
|
||||
// glm-5.3 has no effort curve, so its efforts come from the policy table alone.
|
||||
for (const [model, quotas] of [
|
||||
["claude-opus-5-5", subscription("claude/sub")],
|
||||
["gpt-6-astra", subscription("codex/sub")],
|
||||
["glm-5.3", subscription("glm-5.3/sub")],
|
||||
]) {
|
||||
const cost = (effort) =>
|
||||
evaluateModelQuota(`${model}:${effort}`, effort, { hours: 1.5, difficulty: "hard" }, quotas, {}, t0).opportunity_cost;
|
||||
assert.ok(cost("max") > cost("high") && cost("high") > cost("low"), `${model} max/high/low ${cost("max")}/${cost("high")}/${cost("low")}`);
|
||||
assert.equal(cost("ultra"), cost("max"), `${model} ultra ${cost("ultra")} vs max ${cost("max")}`);
|
||||
for (const effort of ["minimal", "none", "off"]) {
|
||||
assert.ok(cost(effort) < cost("low"), `${model} ${effort} ${cost(effort)} vs low ${cost("low")}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("9.13 The gateway always routes: when every candidate is below the task's floor it sends the most capable one; the allocator itself still declines", async () => {
|
||||
const prompt = "Refactor the payment retry loop in billing/retry.go and add tests for the backoff";
|
||||
const body = () => ({ model: "agentcompass", messages: [{ role: "user", content: prompt }] });
|
||||
const routed = (candidateModels) => {
|
||||
const out = mwOnRequest(body(), { protocol: "chat", agent: "claude-code", options: { candidateModels }, state: {} });
|
||||
return out ? out.model : null;
|
||||
};
|
||||
// AgentCompass may leave a task unrouted; it has nothing below the floor to offer.
|
||||
assert.equal(selectBestRoute(inferTaskProfile({ objective: prompt }), { objective: prompt, candidateModels: ["gpt-6-astra:minimal"] }).ok, false);
|
||||
// Magpie must still send the request somewhere: forwarding `agentcompass` upstream only fails.
|
||||
assert.equal(routed(["gpt-6-astra:minimal"]), "gpt-6-astra:minimal");
|
||||
assert.equal(routed(["gemini-3.8-flash-high"]), "gemini-3.8-flash-high:high");
|
||||
assert.equal(routed(["gpt-6-astra:none", "gpt-6-astra:minimal"]), "gpt-6-astra:minimal");
|
||||
// A candidate that clears the floor still wins.
|
||||
assert.equal(routed(["gpt-6-astra:minimal", "gpt-6-astra:high"]), "gpt-6-astra:high");
|
||||
|
||||
const ctx = { protocol: "chat", agent: "claude-code", options: { scorerType: "heuristic", candidateModels: ["gpt-6-astra:minimal"] }, state: {}, report() {} };
|
||||
await hookOnRequest(body(), ctx);
|
||||
assert.equal(ctx.state.route?.targetModel, "gpt-6-astra");
|
||||
assert.equal(ctx.state.route?.targetEffort, "minimal");
|
||||
assert.ok(ctx.state.route?.fallback, "the decision says it fell back");
|
||||
|
||||
// A model that can't see the request's image is the last resort, however capable it is.
|
||||
const visualPrompt = "Refactor the payment retry loop in billing/retry.go to match this screenshot and add tests for the backoff";
|
||||
const visualBody = () => ({
|
||||
model: "agentcompass",
|
||||
messages: [{
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "text", text: visualPrompt },
|
||||
{ type: "image_url", image_url: { url: "data:image/png;base64,AAAA" } },
|
||||
],
|
||||
}],
|
||||
});
|
||||
const routedVisual = (candidateModels) => {
|
||||
const out = mwOnRequest(visualBody(), { protocol: "chat", agent: "claude-code", options: { candidateModels }, state: {} });
|
||||
return out ? out.model : null;
|
||||
};
|
||||
assert.equal(routedVisual(["claude-fable-5-1:high", "gemini-3.8-flash-high:low"]), "gemini-3.8-flash-high:low");
|
||||
assert.equal(routedVisual(["grok-4.7:high", "gemini-3.8-flash-high:minimal"]), "gemini-3.8-flash-high:minimal");
|
||||
// Outside the floor-only tier, seeing the image still beats raw ability.
|
||||
const visualProfile = { ...inferTaskProfile({ objective: visualPrompt }), needs_visual: true };
|
||||
const kind = visualProfile.work_kind;
|
||||
const seeing = selectBestRoute(visualProfile, {
|
||||
objective: visualPrompt,
|
||||
candidateModels: ["claude-fable-5-1:high", "gemini-3.8-flash-high:low", "grok-4.7:low"],
|
||||
catalog: { routes: { ...CANONICAL_ROUTES, [kind]: { ...CANONICAL_ROUTES[kind], restrict_models: true, preferred: ["grok-4.7"] } } },
|
||||
fallbackToBestExcluded: true,
|
||||
});
|
||||
assert.equal(seeing.modelWithEffort, "gemini-3.8-flash-high:low");
|
||||
assert.equal(seeing.fallback.excluded.length, 2, "not in the allowed list and below the floor");
|
||||
// Only missing the floor beats a capable candidate excluded for another reason.
|
||||
const floorOnly = selectBestRoute(visualProfile, {
|
||||
objective: visualPrompt,
|
||||
candidateModels: ["gpt-6-astra:high", "gemini-3.8-flash-high:low"],
|
||||
catalog: { routes: { ...CANONICAL_ROUTES, [kind]: { ...CANONICAL_ROUTES[kind], restrict_models: true, preferred: ["gemini-3.8-flash-high"] } } },
|
||||
fallbackToBestExcluded: true,
|
||||
});
|
||||
assert.equal(floorOnly.modelWithEffort, "gemini-3.8-flash-high:low");
|
||||
// With no model that can see it, the request still goes somewhere, to the most capable one.
|
||||
assert.equal(routedVisual(["claude-fable-5-1:high", "grok-4.7:high"]), "claude-fable-5-1:high");
|
||||
|
||||
const visualCtx = { protocol: "chat", agent: "claude-code", options: { scorerType: "heuristic", candidateModels: ["claude-fable-5-1:high", "gemini-3.8-flash-high:low"] }, state: {}, report() {} };
|
||||
await hookOnRequest(visualBody(), visualCtx);
|
||||
assert.equal(visualCtx.state.route?.targetModel, "gemini-3.8-flash-high");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user