Add skill governance and runtime routing
This commit is contained in:
1 parent
6f09408423
commit
41dcfcdef7
71 files changed
+7057
-102
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import type { ChatCompletionOptions, ChatMessage } from "@llm/types";
|
||||
import { OnboardingOrchestrator } from "./orchestrator.js";
|
||||
import type { DerivedState } from "../state/onboarding-state.js";
|
||||
import type { Tool } from "@tools/tool";
|
||||
|
||||
function createDerivedState(overrides?: Partial<DerivedState>): DerivedState {
|
||||
return {
|
||||
@@ -17,6 +19,11 @@ function createDerivedState(overrides?: Partial<DerivedState>): DerivedState {
|
||||
}
|
||||
|
||||
describe("OnboardingOrchestrator", () => {
|
||||
afterEach(() => {
|
||||
delete process.env["AGENT_PROGRAMMATIC_TOOL_CALLING"];
|
||||
delete process.env["AGENT_SKILL_MD_MODE"];
|
||||
});
|
||||
|
||||
it("uses direct response path for tier 0", async () => {
|
||||
const calls: Array<{
|
||||
messages: ChatMessage[];
|
||||
@@ -107,6 +114,165 @@ describe("OnboardingOrchestrator", () => {
|
||||
expect(calls[1]?.messages[0]?.content).toContain("[PLAN]");
|
||||
});
|
||||
|
||||
it("runs a planner toolPlan before the responder when enabled", async () => {
|
||||
process.env["AGENT_PROGRAMMATIC_TOOL_CALLING"] = "true";
|
||||
const calls: Array<{
|
||||
messages: ChatMessage[];
|
||||
options: ChatCompletionOptions | undefined;
|
||||
}> = [];
|
||||
const llmClientStub = {
|
||||
chatCompletion: (
|
||||
messages: ChatMessage[],
|
||||
options?: ChatCompletionOptions,
|
||||
) => {
|
||||
calls.push({ messages, options });
|
||||
|
||||
if (calls.length === 1) {
|
||||
return Promise.resolve({
|
||||
content: JSON.stringify({
|
||||
approach: "validate-then-explain",
|
||||
targetPhase: "nickname-rejected",
|
||||
mustInclude: ["검사 결과"],
|
||||
mustAvoid: [],
|
||||
suggestedTools: ["validate-nickname"],
|
||||
toolPlan: {
|
||||
composeWith: "all-then-llm",
|
||||
steps: [
|
||||
{
|
||||
id: "validate",
|
||||
tool: "validate-nickname",
|
||||
argsFromContext: {
|
||||
nickname: "$request.nickname",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
tone: "friendly",
|
||||
targetLengthChars: 120,
|
||||
rationale: "도구 선실행",
|
||||
}),
|
||||
endpoint: "mock://llm",
|
||||
provider: "cliproxy" as const,
|
||||
raw: { choices: [{ message: { content: "{}" } }] },
|
||||
message: { role: "assistant" as const, content: "{}" },
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
content: "검사 결과 형식이 맞아요.",
|
||||
endpoint: "mock://llm",
|
||||
provider: "cliproxy" as const,
|
||||
raw: { choices: [{ message: { content: "검사 결과 형식이 맞아요." } }] },
|
||||
message: { role: "assistant" as const, content: "검사 결과 형식이 맞아요." },
|
||||
});
|
||||
},
|
||||
};
|
||||
const tool: Tool<{ nickname: string }, { valid: boolean }> = {
|
||||
name: "validate-nickname",
|
||||
description: "닉네임 검사",
|
||||
argsSchema: z.object({
|
||||
nickname: z.string(),
|
||||
}),
|
||||
resultSchema: z.object({
|
||||
valid: z.boolean(),
|
||||
}),
|
||||
execute: (args) => Promise.resolve({ valid: args.nickname.includes("/") }),
|
||||
};
|
||||
|
||||
const orchestrator = new OnboardingOrchestrator(llmClientStub as never);
|
||||
const result = await orchestrator.run(
|
||||
createDerivedState({ responseMode: "llm-with-tools", tier: 1 }),
|
||||
[
|
||||
{ role: "system", content: "기본 시스템 프롬프트" },
|
||||
{ role: "user", content: "닉네임 봐줘" },
|
||||
],
|
||||
{
|
||||
request: {
|
||||
requestId: "req-1",
|
||||
skill: "onboarding",
|
||||
chatroomId: "room-1",
|
||||
userId: "user-1",
|
||||
nickname: "프리리/95/여/D",
|
||||
trigger: "user-message",
|
||||
},
|
||||
toolContext: {},
|
||||
tools: [tool],
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toBe("검사 결과 형식이 맞아요.");
|
||||
expect(calls).toHaveLength(2);
|
||||
expect(calls[1]?.messages[0]?.content).toContain("[TOOL_PLAN_RESULTS]");
|
||||
expect(calls[1]?.messages[0]?.content).toContain('"valid":true');
|
||||
expect(calls[1]?.options?.tools).toBeUndefined();
|
||||
});
|
||||
|
||||
it("injects requested SKILL.md resources before responder when enabled", async () => {
|
||||
process.env["AGENT_SKILL_MD_MODE"] = "true";
|
||||
const calls: Array<{
|
||||
messages: ChatMessage[];
|
||||
options: ChatCompletionOptions | undefined;
|
||||
}> = [];
|
||||
const llmClientStub = {
|
||||
chatCompletion: (
|
||||
messages: ChatMessage[],
|
||||
options?: ChatCompletionOptions,
|
||||
) => {
|
||||
calls.push({ messages, options });
|
||||
|
||||
if (calls.length === 1) {
|
||||
return Promise.resolve({
|
||||
content: JSON.stringify({
|
||||
approach: "answer-direct",
|
||||
targetPhase: "photo-pending",
|
||||
mustInclude: ["하트"],
|
||||
mustAvoid: [],
|
||||
suggestedTools: [],
|
||||
requestResources: ["heart-rule"],
|
||||
tone: "friendly",
|
||||
targetLengthChars: 120,
|
||||
rationale: "리소스 참고",
|
||||
}),
|
||||
endpoint: "mock://llm",
|
||||
provider: "cliproxy" as const,
|
||||
raw: { choices: [{ message: { content: "{}" } }] },
|
||||
message: { role: "assistant" as const, content: "{}" },
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve({
|
||||
content: "커버 보기에서 하트를 빨간색으로 바꿔주세요.",
|
||||
endpoint: "mock://llm",
|
||||
provider: "cliproxy" as const,
|
||||
raw: {
|
||||
choices: [
|
||||
{ message: { content: "커버 보기에서 하트를 빨간색으로 바꿔주세요." } },
|
||||
],
|
||||
},
|
||||
message: {
|
||||
role: "assistant" as const,
|
||||
content: "커버 보기에서 하트를 빨간색으로 바꿔주세요.",
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const orchestrator = new OnboardingOrchestrator(llmClientStub as never);
|
||||
const result = await orchestrator.run(
|
||||
createDerivedState({ tier: 1 }),
|
||||
[
|
||||
{ role: "system", content: "기본 시스템 프롬프트" },
|
||||
{ role: "user", content: "하트 어디서 해요?" },
|
||||
],
|
||||
{ toolContext: {} },
|
||||
);
|
||||
|
||||
expect(result).toContain("커버 보기");
|
||||
expect(calls[1]?.messages[0]?.content).toContain("[RESOURCE:heart-rule]");
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("runs critic after responder for tier 2 and applies rewrite", async () => {
|
||||
const calls: Array<{
|
||||
messages: ChatMessage[];
|
||||
|
||||
Reference in new issue
Block a user