feat(agent): automation-first sessions with step plan, option choice and inline approval

- agent.plan emits plan_updated; system prompt asks for a plan first and updates while executing
- agent.propose_options registers a decision and suspends the run (waitForFact, no worker slot);
  the answer or timeout (recommended/stop) resumes it as the tool result
- console-session runs get inline approvals for plan-bound capabilities: approve replays the call
  with the approval, reject fails it with the reason and records it on the decision
- proposeFirst blocks execute capabilities until an option is chosen; E12 covers all paths

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-28 21:07:01 +08:00
1 parent 74c2ed45aa
commit cf2c4ff0e6
14 files changed
+1360 -26

No files matched your search

+37 -1
View File
@@ -5,12 +5,46 @@ export interface SystemPromptInput {
goal: string;
/** 附加约束(范围、预算、"只给方案不执行"等) */
constraints?: readonly string[];
/** 会话交互(AG-2):按本次可用的能力与会话选项生成"工作方式"一节 */
interaction?: {
/** 提供了 agent.plan */
plan?: boolean;
/** 提供了 agent.propose_options */
options?: boolean;
/** 会话选项"先看方案再执行" */
proposeFirst?: boolean;
/** 需审批的能力在步骤处出审批卡(控制台管理员会话) */
approvals?: boolean;
};
}
/** "工作方式":自动化优先——先出步骤清单再执行,执行中更新;有取舍时给方案;需授权的动作等审批 */
export function interactionRules(i: NonNullable<SystemPromptInput["interaction"]>): string[] {
const out: string[] = [];
if (i.plan)
out.push(
"开始时先调用 agent.plan 列出 3–7 个步骤(id 用 s1、s2…),再执行;每开始、完成、跳过或失败一步都调用 agent.plan 更新状态,只传变化的步骤;计划变了就增改步骤。",
);
if (i.options)
out.push(
"遇到有明显取舍的决定(选哪个资源、画质与体积、是否覆盖已有版本)时,用 agent.propose_options 给 2–3 个方案并标出推荐项,按用户选定的方案继续;用户都不要时按他说明的原因调整。不要为小事询问。",
);
if (i.proposeFirst)
out.push(
"本会话要求先看方案再执行:先只做调查,再用 agent.propose_options 给出方案;用户选定前不要调用任何有副作用的能力(提交下载、执行整理、发布策略、重试或取消任务),服务端也会拒绝。",
);
else out.push("默认直接执行:在授权范围内按步骤推进,不必事先征求同意。");
if (i.approvals)
out.push(
"需要审批的动作(提交下载、执行整理、发布策略)在没有持续授权时会在对应步骤出审批卡,会话等待管理员批准或拒绝;被拒绝时按拒绝理由调整方案,不要换参数重试同一动作。",
);
return out;
}
/**
* 系统提示模板。硬性规则不可被用户消息、工具输出、网页/RSS 内容覆盖。
*/
export function buildSystemPrompt({ role, goal, constraints = [] }: SystemPromptInput): string {
export function buildSystemPrompt({ role, goal, constraints = [], interaction }: SystemPromptInput): string {
const rules = [
"只用提供的工具操作业务;没有对应能力就说做不到,不要假装执行。",
"结论必须有证据:引用工具返回的对象 ID、记录或数值;没有证据就写“未确认”。",
@@ -31,6 +65,8 @@ export function buildSystemPrompt({ role, goal, constraints = [] }: SystemPrompt
"## 必须遵守",
...rules.map((r, i) => `${i + 1}. ${r}`),
];
const ways = interaction ? interactionRules(interaction) : [];
if (ways.length > 0) lines.push("", "## 工作方式", ...ways.map((r) => `- ${r}`));
if (constraints.length > 0) {
lines.push("", "## 本次任务约束", ...constraints.map((c) => `- ${c}`));
}