Files
lolympus-agent/src/skills/escalation/trigger.test.ts
T
dahyeon 21df14cd00 Add cost-aware routing and LLM budget tracking
- BudgetTracker tracks LLM token cost separately from tool cost
- LlmClient auto-records cost into request-scoped budget
- Router selects tier from classify confidence, intent risk, escalation count
- Supervisor short-circuits via regex fast-path when rule confidence is high
- Onboarding skill loads user escalation history to inform routing
2026-05-19 01:28:54 -07:00

99 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { HandoffReason } from "@agent/types";
import { decide } from "./trigger.js";
describe("escalation trigger", () => {
it("turns explicit handoff reasons into structured requests", () => {
const reasons: HandoffReason[] = [
"out-of-scope",
"missing-tool",
"low-confidence",
"validation-failed",
"same-agent-revisit",
"max-hop",
"high-risk-action",
"policy-risk",
];
for (const reason of reasons) {
const decision = decide({
classified: { confidence: 0.8 },
reason,
targetAgent: "supervisor",
taskSpec: "review",
});
expect(decision).toMatchObject({
reason,
shouldHandoff: true,
handoff: {
reason,
targetAgent: "supervisor",
taskSpec: "review",
},
});
}
});
it("escalates exhausted budgets and validation rejects", () => {
expect(
decide({
budget: {
estimatedCostUsd: 0,
handoffs: 4,
maxCostUsd: 0.5,
maxHandoffs: 4,
maxSameAgentVisits: 2,
maxToolCalls: 20,
totalCostUsd: 0,
totalLlmCostUsd: 0,
totalToolCostUsd: 0,
toolCalls: 0,
visits: {},
},
}).handoff?.reason,
).toBe("max-hop");
expect(decide({ validation: { status: "reject" } }).handoff?.reason).toBe(
"validation-failed",
);
});
it("escalates low-confidence and uncertain high-risk responses", () => {
expect(
decide({ classified: { confidence: 0.2 } }).handoff?.reason,
).toBe("low-confidence");
expect(
decide({
capabilityCard: {
canHandle: ["policy"],
cannotHandle: [],
domain: "moderation",
handoffTargets: ["supervisor"],
outputContract: { format: "text", maxChars: "500" },
riskTier: "high",
},
classified: { confidence: 0.6 },
}).handoff?.reason,
).toBe("high-risk-action");
});
it("does not escalate ordinary confident responses", () => {
expect(
decide({
capabilityCard: {
canHandle: ["help"],
cannotHandle: [],
domain: "onboarding",
handoffTargets: ["supervisor"],
outputContract: { format: "text", maxChars: "500" },
riskTier: "medium",
},
classified: { confidence: 0.9 },
}),
).toEqual({ shouldHandoff: false });
});
});