在 Antigravity 中使用 agents.md 和 skills.md 构建自主开发者流水线

1. 简介

在此 Codelab 中,我们将向您展示如何使用 Antigravity IDE 在您的计算机上设置一个有趣的 AI 辅助型自主 AI 开发者团队。您将使用强大的 skills.mdagents.md 工作流,通过引导需求完成其整个生命周期(从技术规范到最终部署)来构建一个可正常运行的应用。

我们不会被锁定到特定的技术堆栈或编写复杂的 Python 编排脚本,而是采用友好的零代码方法,让您的需求通过由三个核心 Antigravity 原则驱动的自动化周期:

  1. agents.md:用于准确定义 AI 团队的成员(产品经理、前端、质量检查、DevOps)。
  2. 技能和 skills.md:一个专用目录,您可以在其中将强大的技术能力和工件移交规则定义为模块化 .md 文件。
  3. 工作流 (workflows/):用于定义自定义斜杠命令,这些命令可将 AI 团队成员无缝链接到自主流水线中。

通过在 Antigravity 中以原生方式组合这三个元素,您将引导 Gemini 完全自动地完成从头到尾的可用于生产用途应用开发!

学习内容

  • 初始化工作区:设置项目,以便 Antigravity 能够深入了解。
  • 定义团队:创建 agents.md 文件以建立您的专业 AI 角色。
  • 编写技能程序:在 skills/ 目录中构建详细的 .md 文件,以定义严格的技术规则和迭代返工循环。
  • 定义自定义工作流:创建 /startcycle 斜杠命令以自动执行工作室的工作流。
  • 启动提示链:使用单个命令自动高效地执行整个多智能体流水线!

尝试内容

  • 如何将 AI 提示工程与应用代码分离。
  • 如何构建一个智能体,该智能体能够主动暂停以解读生成的 Markdown 文件中的用户评论和修改。
  • 如何构建动态的、与语言无关的代码生成和部署技能。
  • 如何在智能体 IDE 中构建自定义宏命令(工作流)。

所需条件

准备工作

  1. 确保您已安装 Antigravity IDE (可在 antigravity.google 上获取)。
  2. 打开 Antigravity IDE,并确保您已初始化一个全新的专用 工作区
  3. 在编辑器模式下工作时,请打开终端。

2. 初始化工作区

由于 Antigravity 可以原生理解放置在 .agents 目录中的工作流文件,因此设置自主开发者流水线就像创建几个标准文件夹一样简单。

您可以设置工作区:

  1. 打开 Antigravity IDE
  2. 打开智能体管理器。您可以随时按 CMD+E (Mac) 或 CTRL+E (Windows) 在智能体管理器和编辑器之间切换,也可以通过菜单栏右上角的“打开编辑器”和“打开智能体管理器”按钮进行切换。。
  3. 点击 + 打开工作区

如需在工作区内开始新的对话,请从“开始对话”标签页中选择所需的工作区,或点击边栏中工作区名称旁边的加号按钮。

45e7241be5552e42.png

  1. 点击“打开新工作区”,将工作区命名为 skills-codelab,然后选择本地目录。这样可确保智能体拥有一个特定的根文件夹来搭建文件,而不会使其他项目杂乱无章。完成后,前往编辑器视图,然后执行步骤 (5)、(6) 和 (7)。

d84ba507939a5efc.png

  1. 右键点击并创建 skills-codelab 文件夹。
  2. 在该文件夹内,创建两个目录:production_artifactsapp_build
  3. 创建一个 .agents 目录,并在其中创建 workflowsskills 文件夹。

(可选)如果您更喜欢使用终端,可以立即运行以下命令来生成此结构:

mkdir skills-codelab && cd skills-codelab
mkdir -p .agents/workflows .agents/skills
mkdir production_artifacts app_build

确保您的文件夹如下所示:

7234ea48c2b175a7.png

这些新文件夹有何作用?

  • .agents/:这是一个 Antigravity 原生识别的特殊目录。通过在此处放置文件,您可以扩展 Antigravity 的内置 AI 行为。
  • skills/:此文件夹用于存储 AI 的特定技术说明手册(.md 文件)。这会告诉 AI 如何执行特定任务(例如编写代码或部署应用),从而将一个庞大而令人困惑的提示替换为模块化步骤!
  • production_artifacts/:这是我们的共享文件夹,我们的自动化团队成员会故意将文件放入其中,供下一个智能体读取!
  • app_build/:实际应用代码的指定工作区。全栈工程师智能体将生成所有代码(例如 package.jsonapp.py、React 组件),并将其直接保存到此文件夹中,从而将应用源代码与 AI 的说明隔离开。

3. 定义团队 (agents.md)

首先,我们需要告诉 Antigravity 谁在负责此项目。我们不会将说明保留在四个不同的嵌套项目文件夹中,而是集中管理团队的身份。在 .agents/agents.md 中创建一个文件:

为什么需要不同的角色?

当您要求 AI 从头开始构建整个应用时,如果您强迫 AI 同时担任架构师、编码员、测试人员和部署负责人,AI 很容易不知所措。通过在 agents.md 中集中管理这些角色,您可以防止 AI 感到困惑。产品经理只专注于需求,工程师只专注于代码生成,质量检查人员只专注于 bug 修复。您将为流水线的每个阶段获得专业的专家!

agents.md 文件通过集中管理团队的不同角色来解决此问题:

  1. 产品经理 (@pm):只专注于大局。他们编写 Technical_Specification.md,并与您(人类)一起管理来回审批流程。
  2. 全栈工程师 (@engineer):无需担心规划;他们只需采用产品经理的规范,并完全专注于使用您批准的任何语言编写高质量的代码。
  3. 质量检查工程师 (@qa):充当新的视角。他们不会编写新功能,而是专注于在工程师的代码中查找缺失的依赖项、语法错误或逻辑 bug。
  4. DevOps 主管 (@devops):严格专注于运行时环境。他们知道如何读取终端、安装软件包(npm install、pip install)以及启动本地服务器。
# 🤖 The Autonomous Development Team

## The Product Manager (@pm)
You are a visionary Product Manager and Lead Architect with 15+ years of experience.
**Goal**: Translate vague user ideas into comprehensive, robust, and technology-agnostic Technical Specifications.
**Traits**: Highly analytical, user-centric, and structured. You never write code; you only design systems.
**Constraint**: You MUST always pause for explicit user approval before considering your job done. You are highly receptive to user feedback and will enthusiastically re-write specifications based on inline comments.

## The Full-Stack Engineer (@engineer)
You are a 10x senior polyglot developer capable of adapting to any modern tech stack.
**Goal**: Translate the PM's Technical Specification into a beautiful, perfectly structured, production-ready application.
**Traits**: You write clean, DRY, well-documented code. You care deeply about modern UI/UX and scalable backend logic.
**Constraint**: You strictly follow the approved architecture. You do not make assumptions—if the spec says Python, you use Python. You always save your code into the `app_build/` directory.

## The QA Engineer (@qa)
You are a meticulous Quality Assurance engineer and security auditor.
**Goal**: Scrutinize the Engineer's code to guarantee production-readiness.
**Traits**: Detail-oriented, paranoid about security, and relentless in finding edge cases.
**Focus Areas**: You aggressively hunt for missing dependencies in configurations, unhandled promises, syntax errors, and logic bugs. You proactively fix them.

## The DevOps Master (@devops)
You are the elite deployment lead and infrastructure wizard.
**Goal**: Take the final code in `app_build/` and magically bring it to life on a local server.
**Traits**: You excel at terminal commands and environment configurations.
**Expertise**: You fluently use tools like `npm`, `pip`, or native runners. You install all necessary modules seamlessly and provide the local URL directly to the user so they can see the final product!

请注意,我们如何为每个角色定义目标、特征和约束。

  • 目标告诉智能体在流水线中的确切职责。
  • 特征赋予智能体行为个性,告诉智能体如何行动(例如,“10 倍高级开发者”或“对安全性非常谨慎”)。
  • 约束充当严格的护栏(例如,“绝不编写代码”“严格遵循已批准的架构”)。

以这种方式构建提示可以大幅减少 AI 幻觉,并确保智能体严格遵循您所需的工作流!

确保您的文件夹如下所示:

4. 编写专业技能程序 (skills/)

详细的说明工程是零代码魔法的关键。我们将为每项技能创建高度特定的文本文件,确保产品经理在您请求返工时主动向后循环。

1. 规范技能

此技能充当起点。产品经理智能体使用它来采访您,并在编写任何代码之前充实架构,从而避免浪费数小时的潜在编码时间!

创建 .agents/skills/write_specs.md

# Skill: Write Specs

## Objective
Your goal as the Product Manager is to turn raw user ideas into rigorous technical specifications and **pause for user approval**.

## Rules of Engagement
- **Artifact Handover**: Save all your final output back to the file system.
- **Save Location**: Always output your final document to `production_artifacts/Technical_Specification.md`.
- **Approval Gate**: You MUST pause and actively ask the user if they approve the architecture before taking any further action.
- **Iterative Rework**: If the user leaves comments directly inside the `Technical_Specification.md` or provides feedback in chat, you must read the document again, apply the requested changes, and ask for approval again!

## Instructions
1. **Analyze Requirements**: Deeply analyze the user's initial idea request.
2. **Draft the Document**: Your specification MUST include:
   - **Executive Summary**: A brief, high-level overview.
   - **Requirements**: Functional and non-functional requirements.
   - **Architecture & Tech Stack**: Suggest the absolute best framework (e.g., Python/Django, Node/Express, React/Next.js) for the job and outline the layout/API structure.

   - **State Management**: Briefly outline how data should flow.
3. Save the document to disk.
4. **Halt Execution**: Explicitly ask the user: "Do you approve of this tech stack and specification? You can safely open `Technical_Specification.md` and add comments or modifications if you want me to rework anything!" Wait for their "Yes" or feedback before the sequence continues!

请注意严格的“审批门”。AI 不会一次性构建整个应用并希望它是正确的,而是明确指示 AI 暂停、等待您的最终决定,并在您留下内嵌评论时主动重新阅读文档!

**2. 全栈生成技能

此技能是核心构建器。工程师智能体会从产品经理的规范中读取确切的技术栈,并动态搭建所有必要的前端和后端代码文件。

创建 .agents/skills/generate_code.md

# Skill: Generate Code

## Objective
Your goal as the Full-Stack Engineer is to write the physical code based entirely on the PM's approved specification.

## Rules of Engagement
- **Dynamic Coding**: You are not limited to HTML/JS. You must write code in the exact language/framework defined in the approved `Technical_Specification.md`.
- **Save Location**: Save all your raw code, accurately retaining necessary folder structures, directly inside `app_build/`.

## Instructions
1. **Read the Spec**: Open and carefully study `production_artifacts/Technical_Specification.md`.
2. **Scaffold Structure**: Generate all core backend and frontend application files.
3. **Output**: Dump your code perfectly into the `app_build/` directory. Do not skip or summarize any code blocks. Ensure all `package.json` or `requirements.txt` files are present.

此技能没有预定义堆栈(例如 Next.js 或 Django)。它明确依赖于产品经理选择的动态技术堆栈。这意味着您的单个代码生成技能适用于您在规范中批准的任何框架!

3. 审核技能

此技能提供安全保障。质量检查智能体充当独立审核者,专门负责查找新生成的代码中缺失的依赖项和逻辑错误。

创建 .agents/skills/audit_code.md

# Skill: Audit Code

## Objective
Your goal as the QA Engineer is to ensure the generated code is perfectly functional natively.

## Rules of Engagement
- **Target Context**: Your focus area is the `app_build/` directory.

## Instructions
1. **Assess Alignment**: Compare the raw code against the approved `Technical_Specification.md`.
2. **Bug Hunting**: Find and fix dependency mismatches, unhandled errors, and logic breaks.
3. **Commit Fixes**: Overwrite any flawed files in `app_build/` with your polished revisions.

GenAI 在编写大量代码时自然会犯一些小的语法错误。通过拥有一个单独的“审核技能”,其唯一的工作是查找错误,我们可以大幅提高运行最终应用的成功率。

4. 动态部署技能

此技能使应用栩栩如生。DevOps 智能体确定构建的应用类型(Node、Python 等),并安全地运行安装模块和启动服务器所需的终端命令。

创建 .agents/skills/deploy_app.md

# Skill: Deploy App

## Objective
Your goal as DevOps is to intelligently package the application and fire up a server based on the chosen stack.

## Instructions
1. **Stack Detection**: Inspect the `Technical_Specification.md` and the files in `app_build/` to figure out what stack is being used.

2. **Install Dependencies**: Use your native terminal to navigate into `app_build/` and run `npm install`, `pip install -r requirements.txt`, or whatever is appropriate!

3. **Host Locally**: Execute the appropriate native terminal command (e.g., `npm run dev`, `python3 app.py`) to start a background server.
4. **Report**: Output the clickable localhost link to the user and celebrate a successful launch!

我们利用 IDE 安全运行原生终端命令的功能。

智能体的行为就像真正的 DevOps 工程师一样,根据它在 app_build/ 文件夹中实际看到的文件动态确定要运行的安装命令!

(可选)5. Cloud Run 部署技能

如果您希望将应用直接投入生产环境,而不是仅在本地运行,则可以创建替代部署技能。由于 Antigravity 直接在本地机器上运行,因此 AI 可以无缝利用本地经过身份验证的 gcloud CLI!

创建 .agents/skills/deploy_cloud_run.md

# Skill: Deploy to Cloud Run

## Objective
Your goal as DevOps is to package the application into a container and deploy it to Google Cloud Run.

## Instructions
1. **Verify Environment**: Ensure the necessary files for the chosen tech stack are in `app_build/`.
2. **Containerize**: Use the IDE terminal to navigate to `app_build/` and run `gcloud run deploy --source .`. 
3. **Configure**: If prompted by the CLI tool, automatically select the default region and allow unauthenticated invocations so the web app is public.
4. **Report**: Output the live production Google Cloud Run URL to the user!

5. 定义自定义斜杠命令

自定义斜杠命令的作用是什么?

通过将此文本文件保存在 .agents/workflows/ 中,您可以直接在 Antigravity 的聊天界面中注册一个全新命令!

/startcycle 命令充当自动化编排器,而不是手动逐步提示 AI(“充当产品经理并编写规范…”然后“好的,现在充当工程师并编写代码…”)。它将您定义的角色及其特定技能无缝链接到连续的自动化序列中!我们将创建一个宏来处理智能体之间的移交,明确管理产品经理阶段的返工循环。

创建 .agents/workflows/startcycle.md

---
description: Start the Autonomous AI Developer Pipeline sequence with a new idea
---

When the user types `/startcycle <idea>`, orchestrate the development process strictly using `.agents/agents.md` and `.agents/skills/`.

### Execution Sequence:
1. Act as the **Product Manager** and execute the `write_specs.md` skill using the `<idea>`.
   *(Wait for the user to explicitly approve the spec. If the user provides feedback or adds comments directly to the Markdown file, act as the PM again to re-read and revise the document. Loop this step until they type "Approved").*
2. Shift context, act as the **Full-Stack Engineer**, and execute the `generate_code.md` skill.
3. Shift context, act as the **QA Engineer**, and execute the `audit_code.md` skill.
4. Shift context, act as the **DevOps Master**, and execute the `deploy_app.md` skill.

确保您的文件夹如下所示:

de21eeb6012ddbcd.png

6. 启动提示链!

在 Antigravity 中正式定义团队和规则后,您可以轻松触发整个工作流!

提示 Antigravity:

  1. 在智能体管理器聊天框中,输入 / 以打开自定义命令菜单。选择或输入 startcycle
  2. 提供您的想法:
/startcycle "I need a fast, real-time chat application for customer support on my ecommerce website."

坐下来协作

  1. Gemini 成为产品经理,起草一份可靠的规范,并要求您批准。
  2. 在 IDE 编辑器中打开 Technical_Specification.md,添加一些备注(例如“我们改用 Python 而不是 Node”),然后告知智能体进行返工。它将自主修改文件!
  3. 获得您的批准后,Gemini 会以原生方式将上下文切换到工程师,使用已批准的规范编写后端/前端代码。
  4. 它成为质量检查工程师,修复所有 bug,并保存最终代码。
  5. 最后,DevOps 主管会动态安装模块,并将应用提供给您的浏览器!

Technical_Specification.md 的示例运行,并等待批准或评论

11defe4c48e874cc.png

用户批准提示后,整个工作流开始。

b9af07291806ae60.png

7. 总结与后续步骤

恭喜!您已学习如何将协作迭代循环和动态全栈应用生成注入到智能体流水线中!

在此 Codelab 中,我们介绍了以下内容:

  • 如何使用 .agents/agents.md 映射 AI 角色。
  • .agents/skills/write_specs.md 中构建协作返工循环,以便智能体读取您的内嵌 Markdown 评论。
  • 构建动态 .md 技能,这些技能可以根据已批准的规范使用任何框架(Python、React)编写代码!