【干货】多 AI 协同 + SDD 编程实践:一个 AI 全流程交付实录

前言

2025年以来,AI Coding技术正以前所未有的速度演进,在提升研发效能方面发挥着越来越重要的作用。Claude Code、CodeX、Gemini、Qwen Coder、Kimi K2等编码模型层出不穷,从智能补全到函数生成,再到端到端模块实现,AI Coding已深度融入日常研发流程。

然而,在真实的业务场景中——例如像跨境保险这样涉及多国合规、动态定价、异步交互的复杂领域:

  • 有时,为了让AI模型(ClaudeCode、QwenCoder)理解需求,需要花费数个小时“调试”Prompt,可能最终AI产出的代码是错误的或者并不是我想要的。

  • 有时,受限于单一模型的能力,即使是详细且完善的Prompt,也无法产出预期中的代码。

  • 有时,试图让多个AI协同开发时,却因模型间能力割裂、指令传递依赖人工复制粘贴,导致效率在琐碎中流失。

所以使用AI仅靠“写得快”远远不够,关键在于“写得对”。要实现这一点,需要从依赖感觉的 Vibe Coding 过渡到一个强调规范、可复现、可靠交付的新阶段,SDD(Specification-Driven Development 规范驱动开发) 正是这一转变的核心方法论,并且由多个 AI模型 协同工作,能力互补,避免受限于单一模型的能力边界。

本文基于 SDD 范式,构建了一套由 Claude Code、CodeX 与 Gemini 协同驱动的 AI Coding工作流,并成功从零交付一个跨境保险产品。实践涵盖:「多模型协同互补 + 规范约束」体系的设计与工具选型、Claude Code / CodeX / Gemini 的能力分工与协作机制、以及端到端的开发、审查与归档闭环。

Spec-Driven Development

随着 AI 编码模型的飞速发展,“Vibe Coding”虽能快速产出原型代码,却在研发日常中频频失效:代码看似合理,却偏离业务意图;架构不符合团队约定。问题不在模型本身,而在于仍将 AI 当作“模糊搜索工具”,而非需要明确指令的编码辅助。

Spec-Driven Development(SDD,规范驱动开发)正是对这一范式的根本性修正。SDD的定义由GitHub在25年9月的一篇Blog中提出:

Instead of coding first and writing docs later, in spec-driven development, you start with a (you guessed it) spec. This is a contract for how your code should behave and becomes the source of truth your tools and AI Agents use to generate, test, and validate code. The result is less guesswork, fewer surprises, and higher-quality code.

SDD 核心理念:

1.规范先行,而非文档补写。开发始于对“做什么”和“为什么”的清晰定义——包括业务规则、合规约束、成功标准等。技术细节(如语言、框架)暂不介入。这份规范不是静态文档,而是随着对话可变化的、可被 AI 理解并执行的Contract。

2.分阶段验证,拒绝模糊推进。SDD 将开发拆解为 Specify → Plan → Tasks → Implement 四个明确阶段。每个阶段产出物(规范、技术方案、任务清单)必须经人工确认后,才进入下一阶段。这确保 AI 始终在正确轨道上运行。

3.规范即上下文,赋能多 AI 协同。在多模型协作场景中,统一的规范成为共享语境与约束边界。各模型基于同一份 Spec 工作,避免因理解偏差导致的返工或冲突。

技术选型

目前主流的开源 SDD 工具有三种:Spec Kit(GitHub)、BMAD(社区开源方法论)和 OpenSpec(Fission AI),下面的表格表格总结了这三种工具的核心特点:

尽管 BMAD 在概念完整性上颇具启发性(Behavior-Model-Architecture-Data 分层思想值得借鉴),而 Spec Kit 是GitHub一类的厂商的SDD标准化尝试,但在实际工程落地中,我们面临的核心诉求是:

如何在不改造现有系统、不绑定单一 AI 工具的前提下,快速建立一套可协作、可追溯、可审计的 SDD 工作流。

OpenSpec 正好满足这一需求:

1.轻量可嵌入:OpenSpec 仅通过 CLI 注入即可启用;

2.多 AI 友好:原生支持多种AI工具,当Claude服务异常(例如几天前的CouldFalre服务异常)时,可以换个模型直接顶上,实现“同一份规范,多个模型协同”;

3.变更可管理:保险规则常因政策调整而变更,OpenSpec 的 changes/ 提案机制让每次修改都有记录、可评审、可归档;

所以本文中的实践基于OpenSpec,大家可以结合自己的项目与场景选择合适的SDD工具。

OpenSpec

OpenSpec 是一个轻量级的命令行工具,它通过建立一套清晰的“提案->审查->实现->归档”流程,确保在写代码前,人和AI就“要做什么”达成共识。

┌────────────────────┐│ Draft Change       ││ Proposal           │└────────┬───────────┘         │ share intent with your AI         ▼┌────────────────────┐│ Review & Align     ││ (edit specs/tasks) │◀──── feedback loop ──────┐└────────┬───────────┘                          │         │ approved plan                        │         ▼                                      │┌────────────────────┐                          ││ Implement Tasks    │──────────────────────────┘│ (AI writes code)   │└────────┬───────────┘         │ ship the change         ▼┌────────────────────┐│ Archive & Update   ││ Specs (source)     │└────────────────────┘

多AI模型协作编码

在 OpenSpec 为我们奠定了“规范驱动”的工程基础后,我们面临一个根本矛盾:任务越复杂,越需要多个 AI 模型的能力互补;但手动切换工具、复制粘贴上下文的操作成本,又抵消了 AI 带来的提效红利。

这里我的方法是通过 MCP 协议将 Codex 和 Gemini 作为工具(Tool)注入 Claude并通过全局规则约束,来实现Claude、Codex、Gemini 三位一体的无缝协作。我们只需向 Claude 提出一个需求,它便会自动判断何时调用 Codex 编码、何时调用 Gemini 分析海量文档,并将三位 AI 的输出融合并完整交付——整个过程无需人工干预工具切换。

AI模型的角色与分工

通过配置,我们为这三个模型设定了清晰的职责边界,让它们取长补短:

Claude如何智能决策“调谁”

Claude 并非随机调用,而是严格遵循 CLAUDE.md 配置文件中的全局工具规则,这套规则是强制性的。关键条款如下:

0. Global tool rule For any task that is more than a trivial edit, you MUST:"Can Codex help with code / experiments here?"  "Can Gemini help with large-context analysis here?"

这意味着:工具调用是默认行为,而非可选项。Claude 在每个关键节点都会自问:“Codex 能帮忙吗?Gemini 能帮忙吗?”

这套规则通过三个配置文件来保障:

  • CLAUDE.md:作为“主控面板”,定义了 Claude 作为协调者的决策框架和标准工作流程。

  • 告诉 Claude "你是协调者,需要决定何时调用其他 AI模型;

  • 提供明确的决策框架:"遇到代码问题找 Codex,遇到大文本分析找 Gemini";

  • 定义标准工作流程和 MCP 调用规范;

# CLAUDE.md
## 0. Global tool ruleFor **any research task that is more than a trivial edit**, you MUST:- Ask yourself:    > “Can Codex help with code here?    > Can Gemini help with large-context analysis here?”- If the answer is “yes” for either:  - Call that MCP tool **before** giving a final answer.  - If you skip a tool, briefly explain why.**Tool usage is the default.**---## 1. Language & scope- The user may speak Chinese or English.  - All formal expressions(code, configs, experiments, logs, paper writing, LaTeX) must be in **English**.- Your thinking, planning, coding could be in English.- Routine communication, progress reports, and discussions must be in **Chinese**.---## 2. Roles- **You(Claude)** – orchestrator    - Understand the research goal.    - Split work: read → plan → implement → run → analyze → write.    - Decide when to call Codex / Gemini.    - Apply final code changes and write final text.- **Codex(`codex` mcp tool)** – senior engineer    - Non-trivial code / experiment tasks: design, implementation, debugging, refactor, experiment pipeline.- **Gemini(`gemini-cli` mcp tool)** – large-context analyst    - Many papers, long docs, big codebases, long logs, many runs: global view and pattern finding.Think independently. Tools are advisors, not authorities.---## 3. Typical loop for research tasksFor reproduction, new ideas, ablations, validation, and paper writing:1. **Understand & plan**   - Clarify goal, dataset, baselines, metrics, constraints.   - Summarize a short initial plan.   - **Call Codex** to refine requirements, implementation and experiment design.   - If many files / papers / logs are involved, **call Gemini** for a global view.2. **Implement & run**   - For any non-trivial code or pipeline change:     - **Ask Codex for a unified diff prototype** (donot let Codex apply it).     - You manually rewrite / improve and apply the final code.   - Run experiments with clear configs and logs.3. **Review & analyze**   - After meaningful changes or runs:     - **Call Codex** for code / design review vs the goal.     - For many runs / long logs / big tables, **call Gemini** to find patterns and suggest ablations.   - If Codex and Gemini disagree, ask each to respond to the other, then give your own conclusion.4. **Write**   - Use Gemini for literature & long-text summarization.     - Use Codex for code / pseudo-code snippets and checking method–implementation consistency.     - You write and polish the final English paper text.---## 4. Codex MCP usage(short rules)Tool name: `codex`. Follow the MCP schema; additionally:- **Models**  - Analysis / planning / review → prefer **`gpt-5.1`**    - Action / implementation (code, refactors, pipelines) → prefer **`gpt-5.1-codex`**- **Sandbox & context**  - Default `sandbox = "danger-full-access"`      (the user constrains Codex further via AGENTS.md / environment)。  - Always set `return_all_messages = false`.---## 5. Gemini MCP usage (short rules)Tool name: `gemini-cli`. Follow the MCP schema; additionally:- **Model**  - Always use **`gemini-2.5-pro`**Treat Gemini as **read-only analyst** by default. Implementation andfinal decisions always go through you(and Codex when needed).---## 6. Attitude- Be a careful, critical collaborator.  - Use Codex and Gemini **aggressively** for deeper analysis and cross-checks.  - But the final plan, code, experiments, and claims must:  - pass your own reasoning,  - be clearly explained,  - and be consistent with the data and implementation.
## 7. Others
  • AGENTS.md:Codex 的行为规范

  • 告诉 Codex "你是一个高级工程师,需要遵循这些规则";

  • 规定 Codex 的工作目录(.tmp/)、沟通方式、验证标准;

  • 确保 Codex 的输出符合要求;

# AGENTS.md
## 0) Scope & PrinciplesRules for how the agent(“codex”) communicates, researches, writes code, uses tools, manages files, logs work, and interacts with git inside this repo.---## 1) Communication & Verification(non-negotiable)* **Language parity:** Answer in the language used by the user.* **Factfulness:** Verify inputs; correct mistakes directly.* **No guessing:** If any parameter/constraint is unknown, **ask first**.* **Stepwise:** Break broad tasks into small, verifiable steps.---## 2) Workflow (Plan → Research → Design → Implement → Verify)1. **Plan** the smallest useful increment; note assumptions/risks.2. **Research** before design/coding; cite when relevant.3. **Design** the simplest maintainable approach; confirm ambiguities.4. **Implement** minimally; no scope creep without explicit request.5. **Verify** quickly(checks/tests); surface diffs, outputs, open questions.---## 3) Code & Scope* **Precision:** Short, clear identifiers; few moving parts; maintainable.* **No unsolicited edits:** Don’t change existing code unless asked.* **Keep it small:** Prefer composable utilities over frameworks.---## 4) Tools FirstUse the most appropriate existing tool; don’t re-implement what reliable tools already do well.---## 5) Workspace Layout(everything under `.tmp/`)All files the agent creates **mus…
— 以上为试看内容(约 40%),开通会员后阅读全文 —