Add bounded skill handoff graph

This commit is contained in:
dahyeon committed 2026-05-18 17:22:12 -07:00
1 parent 54bc295ead
commit c14adac162
42 files changed
+2243 -31

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
import type {
AgentRequest,
AgentResponse,
ConversationMessage,
} from "@agent/types";
import { readHandoffPacket } from "@agent/handoff-packet";
import type { GarnetClient } from "@common/garnet";
import type { NatsClient } from "@common/nats";
import { AlertService } from "@obs/alert";
import { metrics } from "@obs/metrics";
import type { Skill } from "@skills/skill";
import type { SkillCapabilityCard } from "@skills/skill-loader";
import { appendSupervisorReview } from "./review-queue.js";
import { routeSupervisorTarget } from "./routing-rules.js";
const CAPABILITY_CARD: SkillCapabilityCard = {
canHandle: ["*"],
cannotHandle: [],
domain: "meta",
handoffTargets: ["onboarding", "moderation"],
outputContract: {
format: "text",
maxChars: "500",
requiredFields: "text",
},
riskTier: "medium",
};
export class SupervisorSkill implements Skill {
readonly name = "supervisor";
readonly priority = 10;
private readonly alertService: AlertService;
constructor(
private readonly garnetClient: Pick<GarnetClient, "appendStream" | "setStringIfAbsent">,
natsClient: Pick<NatsClient, "publish">,
) {
this.alertService = new AlertService(garnetClient, natsClient);
}
canHandle(request: AgentRequest): boolean {
return request.skill === this.name;
}
capabilityCard(): SkillCapabilityCard {
return CAPABILITY_CARD;
}
async handle(
request: AgentRequest,
_conversationHistory: ConversationMessage[],
): Promise<AgentResponse> {
const packet = readHandoffPacket(request);
const target = routeSupervisorTarget(packet);
const reason = packet?.handoffReason ?? "out-of-scope";
await appendSupervisorReview(this.garnetClient, {
chatroomId: request.chatroomId,
reason,
requestId: request.requestId,
target: target ?? "human-review",
userId: request.userId,
});
metrics.humanOverrideTotal.inc({ kind: reason });
await this.alertService.sendAlert(
{
kind: "supervisor-handoff",
metric: "agent.supervisor_handoff",
severity: "warn",
suggestedAction: "Review the supervisor handoff queue.",
threshold: 0,
timestamp: new Date().toISOString(),
value: 1,
window: "request",
},
{
dedupeKey: `lolympus-agent:alert:dedupe:supervisor:${request.requestId}`,
},
);
return {
confidence: 0.6,
metadata: {
supervisorReason: reason,
suggestedTarget: target,
},
requestId: request.requestId,
source: "template",
text: "확인이 필요한 내용이라 운영자에게 전달했어요.",
};
}
}