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
This commit is contained in:
1 parent
211de18476
commit
21df14cd00
16 files changed
+473
-22
No files matched your search
@@ -1,17 +1,53 @@
|
||||
import type { HandoffPacket } from "@agent/handoff-packet";
|
||||
|
||||
export function routeSupervisorTarget(packet: HandoffPacket | undefined): string | null {
|
||||
const text = [
|
||||
export interface SupervisorRuleRoute {
|
||||
confidence: number;
|
||||
target: string | null;
|
||||
}
|
||||
|
||||
const RULES = [
|
||||
{
|
||||
pattern: /(규칙|신고|제재|경고|욕설|광고|홍보|appeal|policy|moderation)/iu,
|
||||
target: "moderation",
|
||||
},
|
||||
{
|
||||
pattern: /(가입|닉네임|하트|인증|디스코드|온보딩|onboarding)/iu,
|
||||
target: "onboarding",
|
||||
},
|
||||
] as const;
|
||||
|
||||
function packetText(packet: HandoffPacket | undefined): string {
|
||||
return [
|
||||
packet?.userGoal,
|
||||
packet?.summary,
|
||||
packet?.handoffReason,
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
if (/(규칙|신고|제재|경고|욕설|광고|홍보|appeal|policy|moderation)/iu.test(text)) {
|
||||
return "moderation";
|
||||
export function routeSupervisorByRules(
|
||||
packet: HandoffPacket | undefined,
|
||||
): SupervisorRuleRoute {
|
||||
const text = packetText(packet);
|
||||
const matches = RULES.filter((rule) => rule.pattern.test(text));
|
||||
|
||||
if (matches.length === 1) {
|
||||
return {
|
||||
confidence: 0.9,
|
||||
target: matches[0]?.target ?? null,
|
||||
};
|
||||
}
|
||||
if (/(가입|닉네임|하트|인증|디스코드|온보딩|onboarding)/iu.test(text)) {
|
||||
return "onboarding";
|
||||
if (matches.length > 1) {
|
||||
return {
|
||||
confidence: 0.6,
|
||||
target: matches[0]?.target ?? null,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
return {
|
||||
confidence: 0,
|
||||
target: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function routeSupervisorTarget(packet: HandoffPacket | undefined): string | null {
|
||||
return routeSupervisorByRules(packet).target;
|
||||
}
|
||||
Reference in new issue
Block a user