V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
xunyu9527
V2EX  ›  程序员

多工作流融合 x10 倍效率提升:多模型 Agent 编排 + Hooks Loop

  •  
  •   xunyu9527 · 21 小时 42 分钟前 · 618 次点击
    推荐中转站: https://nicecode.cc/
    把 /dev 、/omo 、ralph-loop 、/feature-dev 四套工作流融合成一个、多 Agent 并行、多模型后端的功能开发编排器。
    • 一句话启动:/do 实现用户登录功能,剩下的交给 AI
    • 7 阶段完整覆盖:Discovery → Exploration → Clarification → Architecture → Implementation → Review → Summary
    • 多 Agent 并行:code-explorer 、code-architect 、code-reviewer 、develop 各司其职
    • 多模型后端:分析用 grok-code ,架构用 opus4.5 ,代码用 gpt5.2 ,按任务特性分配最优模型,可以自定义配置
    • Loop 机制保障:Stop Hook 阻止意外退出,确保流程完整执行

    为什么做这个融合?
    继 /dev /omo 之后一直在思考如何将这些好用的工作流融合起来,够快够智能够好用
    1. 需要 dev 的快、简单
    2. 需要 omo 的多模型 agent 编排
    3. 需要 ralph-loop 能够保证任务最终完成
    4. 需要主动沟通确定方案
    基于上面的内容我突然想到把他们全部融合在一起不就好了吗,于是就有了 do 。
    Do 的核心参考来源:
    来源 贡献
    feature-dev 7 阶段工作流框架 + Agent 分工 + Context Pack 模板
    dev 需求澄清机制 + 多后端路由 + 90% 覆盖率要求
    omo 路由优先编排 + 最小 Agent 集选择 + 编排者不写代码原则
    ralph-loop Stop Hook 防中断 + 状态文件持久化 + 完成信号机制

    核心设计:编排者不写代码
    这个设计来自 omo 的核心理念。do 的第一条铁律:
    Claude Code 只负责编排,所有代码变更必须委托给 codeagent-wrapper 中的 Agent 。
    这不是因为 Claude Code 写不了代码,而是因为:
    • 职责分离:编排者专注流程控制,执行者专注代码质量
    • 模型专长:不同 Agent 可以用不同后端( Codex 、Claude 、Gemini )
    • 可追溯性:每个 Agent 的输出都有独立日志和上下文
    # 这是编排者的正确姿势
    codeagent-wrapper --agent develop - . <<'EOF'
    ## Original User Request
    /do 添加用户登录功能

    ## Context Pack
    - Code-explorer output: [Phase 2 分析结果]
    - Code-architect output: [Phase 4 架构方案]

    ## Current Task
    实现登录功能,遵循现有模式

    ## Acceptance Criteria
    端到端可用;测试通过; diff 最小化
    EOF

    7 阶段工作流详解
    Phase 1: Discovery - 理解需求
    目标:搞清楚要做什么。不是直接开干,而是先用 AskUserQuestion 问清楚:
    • 用户可见的行为是什么?
    • 范围边界在哪?
    • 验收标准是什么?
    然后调用 code-architect 生成需求清单和澄清问题。
    codeagent-wrapper --agent code-architect - . <<'EOF'
    ## Current Task
    Produce requirements checklist and identify missing information.
    Output: Requirements, Non-goals, Risks, Acceptance criteria, Questions (<= 10)

    ## Acceptance Criteria
    Concrete, testable checklist; specific questions; no implementation.
    EOF

    Phase 2: Exploration - 探索代码库
    目标:搞清楚现有代码怎么写的。
    Phase 2: Exploration
    目标:映射代码库模式和扩展点。并行运行 3 个探索任务。
    ---TASK---..)
    Bash(codeagent-wrapper --parallel <<'EOF' timeout: 5m 0s
    ===
    Execution Report ==:
    3 tasks I 3 passed I 0 failed
    ... +27 lines (ctrl+o to expand)
    这里体现了 并行优先 原则——三个 code-explorer 任务同时跑:
    codeagent-wrapper --parallel <<'EOF'
    ---TASK---
    id: p2_similar_features
    agent: code-explorer
    workdir: .
    ---CONTENT---
    Find 1-3 similar features, trace end-to-end.
    Return: key files with line numbers, call flow, extension points.

    ---TASK---
    id: p2_architecture
    agent: code-explorer
    workdir: .
    ---CONTENT---
    Map architecture for relevant subsystem.
    Return: module map + 5-10 key files.

    ---TASK---
    id: p2_conventions
    agent: code-explorer
    workdir: .
    ---CONTENT---
    Identify testing patterns, conventions, config.
    Return: test commands + file locations.
    EOF

    三个探索任务并行执行,结果合并后传递给下一阶段。

    Phase 3: Clarification - 澄清疑问(强制阶段)
    目标:解决所有模糊点。这是 不可跳过 的阶段。Phase 1 和 Phase 2 的输出汇总后,让 code-architect 生成优先级排序的问题列表,然后用 AskUserQuestion 逐一确认。
    ## 澄清问题

    1. 登录失败时,错误信息是否需要区分"用户不存在"和"密码错误"?
    2. 是否需要支持"记住我"功能?
    3. 密码重置流程是否在本次范围内?
    不回答不进入下一阶段。这是从 ralph-loop 学来的——宁可多问,不要猜错。

    Phase 4: Architecture - 设计方案
    目标:确定怎么实现。
    同样是并行模式——两个 code-architect 同时工作,提出两种方案:
    第四阶段:架构设计目标:产出实现方案。并行运行两套设计。
    Bash(codeagent-wrapper --parallel <<'EOF' timeout: 5m Os

    方案 特点
    minimal-change 复用现有抽象,最小化新文件
    pragmatic-clean 引入测试友好的接缝,更好的可维护性
    codeagent-wrapper --parallel <<'EOF'
    ---TASK---
    id: p4_minimal
    agent: code-architect
    workdir: .
    ---CONTENT---
    Propose minimal-change architecture: reuse existing abstractions.
    Output: file touch list, risks, edge cases.

    ---TASK---
    id: p4_pragmatic
    agent: code-architect
    workdir: .
    ---CONTENT---
    Propose pragmatic-clean architecture: introduce seams for testability.
    Output: file touch list, testing plan, risks.
    EOF

    用户选择后,进入实现阶段。

    Phase 5: Implementation - 实现(需审批)
    目标:把代码写出来。
    这个阶段有个 显式审批门:
    用 AskUserQuestion 确认:
    "Approve starting implementation?"
    - Approve
    - Not yet
    已批准。开始实现。
    将实现分为 3 个批次
    1.后端:数据模型+API
    2.前端 Store + Service¥3.前端:页面+入口修改
    ## Original User Request..)[codeagent-wrapper]Backend: codex
    Bash(codeagent-wrapper --agent develop -. <<'EOF' ti
    Command: codex e --dangerously-bypass-approvals-

    codeagent-wrapper --agent develop - . <<'EOF'
    ## Context Pack
    - Code-explorer output: [Phase 2 全部输出]
    - Code-architect output: [Phase 4 选定方案 + Phase 3 答案]

    ## Current Task
    Implement with minimal change set following chosen architecture.
    - Follow Phase 2 patterns
    - Add/adjust tests per Phase 4 plan
    - Run narrowest relevant tests

    ## Acceptance Criteria
    Feature works end-to-end; tests pass; diff is minimal.
    EOF

    Phase 6: Review - 代码审查
    目标:抓 bug 、砍复杂度。
    两个 code-reviewer 并行工作:
    审查者 关注点
    correctness 正确性、边界情况、失败模式
    simplicityKISS 原则、消除冗余抽象
    codeagent-wrapper --parallel <<'EOF'
    ---TASK---
    id: p6_correctness
    agent: code-reviewer
    workdir: .
    ---CONTENT---
    Review for correctness, edge cases, failure modes.
    Assume adversarial inputs.

    ---TASK---
    id: p6_simplicity
    agent: code-reviewer
    workdir: .
    ---CONTENT---
    Review for KISS: remove bloat, collapse needless abstractions.
    EOF

    审查结果出来后,用户决定:• Fix now (现在修)• Fix later (以后修)• Proceed as-is (直接过)

    Phase 7: Summary - 总结文档
    目标:记录做了什么。
    最后一个 code-reviewer 调用,生成完成报告:
    • 做了什么• 关键决策和取舍• 修改的文件路径• 验证命令• 后续工作(可选)完成后输出完成信号:
    <promise>DO_COMPLETE</promise>

    多模型后端:按任务选模型
    codeagent-wrapper 支持为不同 Agent 配置不同后端。
    在 ~/.codeagent/models.json 中:
    {
      "agents": {
        "code-explorer": {
          "backend": "opencode",
          "model": "opencode/grok-code",
          "description": "快速代码分析"
        },
        "code-architect": {
          "backend": "claude",
          "model": "claude-opus-4-5-20251101",
          "description": "深度架构设计"
        },
        "code-reviewer": {
          "backend": "claude",
          "model": "claude-sonnet-4-5-20250929",
          "description": "代码审查"
        },
        "develop": {
          "backend": "codex",
          "model": "gpt-5.2",
          "description": "代码实现"
        }
      }
    }

    为什么这样分配?
    Agent 推荐后端 原因
    code-explorer grok-code 快速遍历、代价低
    code-architect opus4.5 需要深度思考、权衡取舍
    code-reviewer sonnet 平衡速度和质量
    develop gpt-5.2 代码生成能力强、执行稳定

    Loop 机制:防止中途退出
    这是从 ralph-loop 借鉴的核心机制。
    状态文件
    每次 /do 启动时,创建 .claude/do.local.md
    ---
    active: true
    current_phase: 1
    phase_name: "Discovery"
    max_phases: 7
    completion_promise: "<promise>DO_COMPLETE</promise>"
    ---
    每完成一个阶段,更新 current_phase 和 phase_name 。
    Stop Hook
    安装后会注册 Stop Hook 。当 Claude 尝试退出时:
    # hooks/stop-hook.sh 核心逻辑
    if [ "$phases_done" -eq 0 ]; then
      reason="feature-dev 循环未完成:当前阶段 ${current_phase}/${max_phases}..."
      printf '{"decision":"block","reason":"%s"}\n' "$reason"
    fi
    如果还没完成,Hook 会 阻止退出 并提示继续执行。
    强制退出方式:将状态文件中 active 设为 false 。

    安装与使用
    前置条件
    1. 安装 codeagent-wrapper:
    git clone https://github.com/cexll/myclaude.git
    bash ./install.sh
    2. 配置至少一个后端 CLI:
    • codex ( OpenAI Codex CLI )
    • claude ( Claude Code CLI )
    安装 Skill
    python install.py --module do
    安装内容:
    • ~/.claude/skills/do/ - Skill 文件
    • Hooks 自动合并到 ~/.claude/settings.json
    使用
    # 在 Claude Code 中
    /do 添加用户登录功能
    /do 实现订单导出 CSV
    /do feature-prd.md

    卸载
    python install.py --uninstall --module do

    自定义 Agent Prompt
    Agent 提示词位于 ~/.claude/skills/do/agents/ 目录:
    • code-explorer.md - 代码追踪、架构映射
    • code-architect.md - 方案设计、文件规划
    • code-reviewer.md - 代码审查、简化建议
    如需自定义,在 ~/.codeagent/agents/ 创建同名文件覆盖。

    #总结
    do 是四套工作流的合体
    • feature-dev 的 7 阶段框架和 Agent 分工
    • dev 的需求澄清和多后端路由• omo 的智能路由和编排者不写代码原则
    • ralph-loop 的状态持久化和防中断机制加上 codeagent-wrapper 的多后端支持,你可以:
    1. 用一条命令启动完整的功能开发流程
    2. 让不同模型各展所长
    3. 通过并行执行提升效率
    4. 借助 Loop 机制确保流程完整
    我做的工作就是把这些优秀的设计拼到一起,形成一套可复制的 AI 编排方法论。
    转载:公众号 [星纬智联技术] ,推荐中转站: https://nicecode.cc/
    2 条回复    2026-02-10 22:41:28 +08:00
    thevenin1416
        1
    thevenin1416  
       20 小时 35 分钟前
    实际效果怎么样?
    xunyu9527
        2
    xunyu9527  
    OP
       20 小时 6 分钟前
    还不错
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2254 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:47 · PVG 18:47 · LAX 02:47 · JFK 05:47
    ♥ Do have faith in what you're doing.