51 lines
2.5 KiB
TypeScript
51 lines
2.5 KiB
TypeScript
import { buildLayeredPrompt } from "./prompt/assemble.ts";
|
|
import type { EnvironmentFacts, InteractionOptions, SessionKind, SkillDoc } from "./prompt/types.ts";
|
|
|
|
// 系统提示入口(AG-5 起分层,见 ./prompt/):
|
|
// ① 角色与边界 prompt/layers/role.ts ② 环境事实 prompt/layers/environment.ts
|
|
// ③ 能力地图 prompt/layers/capabilities.ts ④ Skill prompt/skills.ts(按意图载入 packages/agent/skills)
|
|
// ⑤ 行为规则 prompt/layers/behavior.ts ⑥ 汇报规则 prompt/layers/report.ts
|
|
// 组装与按会话类型选层见 prompt/assemble.ts。prompt 回归测试:packages/agent/test/system-prompt.test.ts。
|
|
|
|
export { interactionRules } from "./prompt/layers/behavior.ts";
|
|
export { AGENT_REPORT_FORMAT, REPORT_FORMAT } from "./prompt/layers/report.ts";
|
|
|
|
export interface SystemPromptInput {
|
|
/** 角色,例如 "媒体库自动化智能体" / "下载失败诊断员" */
|
|
role: string;
|
|
/** 本次有界任务的目标 */
|
|
goal: string;
|
|
/** 附加约束(范围、预算、"只给方案不执行"等) */
|
|
constraints?: readonly string[];
|
|
/** 会话交互(AG-2):按本次可用的能力与会话选项生成"工作方式" */
|
|
interaction?: InteractionOptions;
|
|
/**
|
|
* 汇报给谁看:user(缺省)按「汇报格式」写给用户;agent = 子会话 / 视觉子流程,汇报给父会话汇总,
|
|
* 可以带对象 ID。给了 kind 时以 kind 为准。
|
|
*/
|
|
audience?: "user" | "agent";
|
|
/** 会话类型(决定装配哪些层);缺省按 audience 推断:user → chat,agent → vision */
|
|
kind?: SessionKind;
|
|
/** 本次可用的能力(能力地图只列这些) */
|
|
capabilities?: readonly string[];
|
|
/** 环境事实 */
|
|
environment?: EnvironmentFacts | null;
|
|
/** 已载入与可用的 Skill */
|
|
skills?: { loaded: readonly SkillDoc[]; available?: readonly SkillDoc[] };
|
|
}
|
|
|
|
/** 系统提示模板。硬规则不可被用户消息、工具输出、网页/RSS 内容覆盖。 */
|
|
export function buildSystemPrompt(input: SystemPromptInput): string {
|
|
const kind: SessionKind = input.kind ?? (input.audience === "agent" ? "vision" : "chat");
|
|
return buildLayeredPrompt({
|
|
kind,
|
|
role: input.role,
|
|
goal: input.goal,
|
|
...(input.constraints ? { constraints: input.constraints } : {}),
|
|
...(input.interaction ? { interaction: input.interaction } : {}),
|
|
...(input.capabilities ? { capabilities: input.capabilities } : {}),
|
|
...(input.environment ? { environment: input.environment } : {}),
|
|
...(input.skills ? { skills: input.skills } : {}),
|
|
});
|
|
}
|