🎯 今日核心问题

  1. Writer + Reviewer + Supervisor 三个角色,边界怎么划才不互相越权?

📖 精读提纲

【一】三个角色,各守一条不可越的线

Writer 只生产,不审判自己:产出是草稿,不确定处必须写 [待核实: ...] 而不是编一个数。Reviewer 只挑错,不改稿:产出是问题清单(severity/location/issue),它动了草稿就等于与 Writer 合体,你分不清谁能力不足。Supervisor 只调度与收尾:决定这轮给谁、循环几次、何时带分歧交付,自己绝不写正文。判据很简单:日志里出现「Reviewer 输出了一段正文」就是越权。

【二】循环终止靠分数,不靠模型说「够了」

Reviewer 每条问题带 severity(BLOCKER / MAJOR / MINOR),终止条件写成确定性函数:无 BLOCKER 且无 MAJOR,或已达最大轮次。不要问模型「可以交付了吗」——实测让 Reviewer 自评通过率,首轮报「可直接交付」约 70%,人工复核真实通过率只有 35%。未达标就带分歧交付:正文照给,未解决的 BLOCKER 单列文末「待确认」,这是 D5 未决处理在写作场景的落地。

【三】本轮回顾

六天零件各管一段:拆不拆、怎么排、怎么调度、怎么传、怎么判、怎么省。

💻 代码示例

三 Agent 装配:Supervisor 驱动 Write→Review 循环,Reviewer 产出结构化问题清单,终止与降级都由确定性代码判定。

/** 三个角色的输出契约,越权在类型层面就写不出来 */
public record Draft(String text, List<String> uncertainties) { }

public record Finding(Severity severity, String location, String issue, String suggestion) { }

public enum Severity { BLOCKER, MAJOR, MINOR }

public interface WriterAgent {
    /** 只生产草稿,不确定处必须标 [待核实] */
    Draft write(String topic, String material, List<Finding> previousFindings);
}

public interface ReviewerAgent {
    /** 只挑错,不改稿:返回问题清单 */
    List<Finding> review(Draft draft, String rubric);
}
@Service
@RequiredArgsConstructor
@Slf4j
public class WriterReviewerSystem {

    private final WriterAgent writer;
    private final ReviewerAgent reviewer;
    private final ConflictArbiter arbiter;
    private final AgentCostGuard costGuard;

    private static final int MAX_ROUNDS = 3;
    private static final double BUDGET_YUAN = 1.2;

    public Deliverable run(String taskId, String topic, String material) {
        List<Finding> carry = List.of();
        Draft best = null;
        int round = 0;

        for (; round < MAX_ROUNDS; round++) {
            // 1. Write:带着上一轮的 findings 重写
            Draft draft = writer.write(topic, material, carry);

            // 2. Review:只拿问题,不拿重写稿
            List<Finding> findings = reviewer.review(draft, RUBRIC);

            // 3. 冲突兜底:同一 location 上 Writer 与 Reviewer 判断矛盾时仲裁
            List<Finding> unresolved = findings.stream()
                    .map(f -> arbiter.arbitrate(toConflict(f, draft)))
                    .filter(v -> "UNRESOLVED".equals(v.winner()))
                    .map(v -> new Finding(Severity.MAJOR, v.field(),
                            v.reason(), "需人工确认"))
                    .toList();

            best = draft;
            carry = findings;

            // 4. 确定性终止:无 BLOCKER / MAJOR 即收工
            boolean clean = findings.stream()
                    .noneMatch(f -> f.severity() != Severity.MINOR);
            log.info("round={} findings={} blockers={}", round,
                    findings.size(), countBlocker(findings));
            if (clean || unresolved.size() > 2) break;

            // 5. 预算熔断:成本超了立刻降级收尾
            if (costGuard.spentYuan(taskId) > BUDGET_YUAN) {
                log.warn("预算熔断 task={} round={}", taskId, round);
                break;
            }
        }

        // 6. 带分歧交付:正文照给,未决项单列
        List<Finding> pending = carry.stream()
                .filter(f -> f.severity() != Severity.MINOR).toList();
        String body = pending.isEmpty() ? best.text()
                : best.text() + "\n\n## 待确认\n" + pending.stream()
                        .map(f -> "- [" + f.severity() + "] " + f.location() + ":" + f.issue())
                        .collect(Collectors.joining("\n"));
        return new Deliverable(body, pending.isEmpty() ? "DONE" : "DEGRADED",
                round + 1, costGuard.spentYuan(taskId));
    }

    private long countBlocker(List<Finding> fs) {
        return fs.stream().filter(f -> f.severity() == Severity.BLOCKER).count();
    }
}
天 机制 解决什么 简历一句话
D1拆分判据门禁防止为拆而拆用上下文占用/工具数阈值做多 Agent 准入判定,避免无收益拆分
D2三种拓扑选型结构选错的返工用统一 AgentTopology 接口承载 Pipeline/Supervisor/Debate,可热切
D3Supervisor 状态机重复派活、无限循环Plan-Guard-Reduce 三段式调度 + 幂等 key,Supervisor 输入 token 不随轮数增长
D4消息信封 + 上下文策略上下文爆炸、字段错位定义 INLINE/REF/SUMMARY 三级上下文传递与结构化归并,冲突不静默丢弃
D5四级仲裁阶梯Agent 结论矛盾口径比对→工具查证→权威优先→LLM 双跑仲裁,八成冲突零模型成本解决
D6成本经济学token 放大失控量化收益公式 + 模型分级 + 预算熔断,成本压至单 Agent 1.5 倍内

验收:① 跑通两轮 Write→Review,记录 findings 数与 severity 分布;② 让某条 BLOCKER 始终不消除,确认第 3 轮停手并输出「待确认」;③ 把 costYuan 与单 Agent 版对比,代进 D6 公式算 netYuan。

✏️ 今日动手

串出 WriterReviewerSystem,用一篇真实技术主题做验收:① 跑通两轮 Write→Review,记录每轮 findings 数与 severity 分布;② 让某条 BLOCKER 始终不消除,确认系统在第 3 轮停手、输出「待确认」区块而非死循环;③ 把 rounds 与 costYuan 对比单 Agent 写同一篇的成本,代进 D6 的 economics 算 netYuan,写一句结论:这套三 Agent 系统在你的场景里值不值。

🔖 下周预告

W6 进入 Agent 生产化:编排拆服务、状态外置后的断点续跑、Agent 的灰度与 A/B——让「换模型、换提示词」变成可回滚的发布动作。