Google Antigravity Skills 完整使用指南
一、创建 Skills 的步骤
1.1 确定 Skill 的作用域
选择存放位置:
1.2 创建 Skill 文件夹
# 项目级 Skill
mkdir -p .agent/skills/my-skill
# 全局 Skill
mkdir -p ~/.gemini/antigravity/skills/my-skill
1.3 创建必需的 SKILL.md 文件
cd .agent/skills/my-skill
touch SKILL.md
1.4 (可选)添加其他资源
# 创建可选的目录结构
mkdir scripts # 存放 Python 或 Bash 脚本
mkdir references # 存放文档、示例
mkdir resources # 存放模板文件
完整的 Skill 目录结构示例:
my-skill/
├── SKILL.md # 必需:元数据和指令
├── scripts/ # 可选
│ ├── deploy.sh
│ └── test_runner.py
├── references/ # 可选
│ └── api_examples.md
└── resources/ # 可选
└── template.json
二、SKILL.md 书写格式
2.1 基本格式结构
---
name: skill-name
description: 用第三人称描述这个 Skill 的功能和使用场景,包含关键词
---
# Skill 标题
## 何时使用
- 列出适用场景
- 触发条件
## 使用方法
具体的步骤、规范、示例代码
## 注意事项
特殊说明、限制条件
2.2 关键要素说明
Frontmatter(前置元数据)
name:Skill 的唯一标识符,使用小写和连字符description:最重要,决定 Agent 是否激活此 Skill- 使用第三人称
- 包含关键词和使用场景
- 清晰、具体、可搜索
好的 description 示例:
description: Generates unit tests for Python code using pytest conventions and mocking best practices
不好的 description 示例:
正文内容
- 何时使用:明确列出触发条件
- 使用方法:详细的步骤、代码示例、规范
- 注意事项:限制、依赖、特殊说明
2.3 完整示例模板
---
name: pytest-generator
description: Generates comprehensive unit tests for Python functions using pytest framework with fixtures, mocking, and edge case coverage
---
# Python Pytest 测试生成器
## 何时使用
- 当需要为 Python 函数或类生成单元测试时
- 当要求使用 pytest 框架时
- 当需要包含 mock、fixture 或参数化测试时
## 使用方法
### 1. 测试文件命名
- 测试文件命名:`test_<module_name>.py`
- 测试函数命名:`test_<function_name>_<scenario>`
### 2. 基本测试结构
```python
import pytest
from module import function_to_test
def test_function_to_test_basic_case():
# Arrange
input_data = ...
expected = ...
# Act
result = function_to_test(input_data)
# Assert
assert result == expected
3. 必须包含的测试类型
- 正常情况测试
- 边界条件测试
- 异常情况测试
- 参数化测试(使用
@pytest.mark.parametrize)
4. Mock 使用规范
使用 pytest-mock 或 unittest.mock 进行依赖隔离
注意事项
- 测试覆盖率应达到 80% 以上
- 每个测试函数只测试一个功能点
- 使用有意义的断言消息
---
## 三、调用方法
### 3.1 全局调用(Global Skills)
**设置步骤:**
1. **创建全局 Skill**
```bash
mkdir -p ~/.gemini/antigravity/skills/code-style
cd ~/.gemini/antigravity/skills/code-style
- 编写 SKILL.md
---
name: python-code-style
description: Enforces Python code formatting using Black, isort, and type hints following PEP 8 standards
---
# Python 代码风格规范
## 何时使用
- 编写或修改 Python 代码时
- 需要格式化代码时
- 添加类型注解时
## 使用方法
1. 使用 Black 格式化,行长度 88
2. 使用 isort 排序导入
3. 添加类型提示
4. 遵循 PEP 8 命名规范
- 在任何项目中自动生效
# 在任意项目目录下
cd ~/my-project
# Agent 会自动加载全局 Skills
使用场景:
3.2 项目级调用(Workspace Skills)
设置步骤:
- 在项目根目录创建 Skill
cd ~/my-project
mkdir -p .agent/skills/deploy
cd .agent/skills/deploy
- 编写项目特定的 SKILL.md
---
name: kubernetes-deploy
description: Deploys application to production Kubernetes cluster using Helm charts with blue-green deployment strategy
---
# Kubernetes 部署流程
## 何时使用
- 当需要部署到生产环境时
- 当提到 "deploy" 或 "发布" 时
## 使用方法
1. 检查 `values.yaml` 配置
2. 运行 `helm upgrade --install`
3. 验证 Pod 状态
4. 执行健康检查
## 部署脚本
参考 `scripts/deploy.sh`
- 提交到版本控制
git add .agent/skills/
git commit -m "Add deployment skill"
git push
团队协作:
- 团队成员克隆仓库后自动获得相同的 Skills
- 保持工作流程一致性
四、实际案例演示
案例 1:Git 提交信息格式化
目录结构:
.agent/skills/git-commit/
└── SKILL.md
SKILL.md 内容:
---
name: conventional-commits
description: Formats Git commit messages following Conventional Commits specification with type, scope, and description
---
# Git 提交信息规范
## 何时使用
- 执行 git commit 时
- 需要生成或修改提交信息时
- 当用户提到 "commit" 或"提交"时
## 提交格式
### 基本结构
():