# Trae 集成

在 Trae（字节跳动 AI IDE，国内最大的 AI 编程工具）中直接运行多角色工作流，无需 API key。

> 🌐 **English users:** `npm install -g agency-orchestrator` — both 211 Chinese and 170+ English roles are bundled. Use `ao compose "your idea" --run` from CLI, or follow this guide for IDE-specific setup (translations coming in v0.6).

## 安装

```bash
# 1. 下载 211 个 AI 角色
cd your-project
git clone --depth 1 https://github.com/jnMetaCode/agency-agents-zh.git

# 2. 下载工作流模板和技能文件
git clone --depth 1 https://github.com/jnMetaCode/agency-orchestrator.git .ao-tmp
cp -r .ao-tmp/workflows ./workflows
mkdir -p .trae/rules
cp .ao-tmp/integrations/trae/ao-workflow-runner.md .trae/rules/
rm -rf .ao-tmp

# 3. 开始使用
# 在 Trae 中直接说：运行 workflows/story-creation.yaml
```

## 使用方式

### 方式一：Skill 模式（推荐，零配置）

将 `ao-workflow-runner.md` 复制到 `.trae/rules/` 后，Trae 会自动加载该规则文件。在 Trae 中直接说：

```
运行 workflows/story-creation.yaml，创意是"一个程序员在凌晨发现AI回复不该知道的事"
```

或者不用 YAML 文件，直接描述协作需求：

```
用叙事学家设计结构，心理学家塑造人物，内容创作者执笔，帮我写一个关于时间旅行的故事
```

Trae 会自动：
- 解析工作流 / 生成工作流
- 按 DAG 顺序加载每个角色
- 扮演角色执行每一步
- 将结果保存到 `ao-output/`

### 方式二：CLI 模式（需要 API key）

如果你需要批量执行、CI/CD 集成或脚本调用：

```bash
npm install -g agency-orchestrator
export DEEPSEEK_API_KEY=sk-xxx   # 或 ANTHROPIC_API_KEY / OPENAI_API_KEY
ao run workflows/story-creation.yaml -i 'premise=时间旅行的故事'
```

## 对比

| 特性 | Skill 模式 | CLI 模式 |
|------|:----------:|:--------:|
| 需要 API key | 不需要 | 需要 |
| 需要安装 | ao-workflow-runner.md → .trae/rules/ | agency-orchestrator |
| 执行环境 | Trae 会话内 | 终端 |
| 并行执行 | 代理按 DAG 层级依次执行 | Promise.allSettled |
| 适合场景 | 交互式、一次性任务 | 批量、自动化、CI/CD |
| 输出 | 会话内 + 文件 | 文件 |

## 可用工作流

| 工作流 | 文件 | 说明 |
|--------|------|------|
| 短篇小说创作 | `story-creation.yaml` | 叙事学家 → 心理学家 + 叙事设计师 → 内容创作者 |
| 产品需求评审 | `product-review.yaml` | 产品经理 → 架构师 + UX 研究员 → 产品经理 |
| 内容流水线 | `content-pipeline.yaml` | 策略师 → 创作者 + SEO → 编辑 |

## 自定义工作流

创建你自己的 YAML 工作流文件：

```yaml
name: "我的工作流"
agents_dir: "agency-agents-zh"

inputs:
  - name: topic
    description: "主题"
    required: true

steps:
  - id: research
    role: "marketing/marketing-content-strategist"
    task: "研究以下主题的内容策略：{{topic}}"
    output: strategy

  - id: write
    role: "marketing/marketing-content-creator"
    task: "根据以下策略撰写文章：{{strategy}}"
    depends_on: [research]
```

查看所有可用角色：

```bash
ao roles
# 或在 Trae 中说：列出 agency-agents-zh 里的所有角色
```
