# create()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/workflows/create/
Language: zh

`api.workflows.create(definition) → Promise<Workflow>`

验证整个定义并保存它。 所有可以检查的内容都在这里检查, 您仍然在读信件 。

Status: POST /api/workflows · validated on save · tools are serialised

```javascript
const workflow = await api.workflows.create({
  name: "Triage",
  trigger: { type: "manual" },
  steps: [
    { id: "classify", type: "model.generate", config: { model: "gemini-3.5-flash",
        prompt: "Is this urgent? {{input.text}}", schema: { type: "object", properties: { urgent: { type: "boolean" } } } } },
    { id: "check",    type: "condition", config: { left: "{{steps.classify.output.urgent}}", operator: "eq", right: true } },
    { id: "approve",  type: "human", config: { title: "Send the alert?" } },
    { id: "alert",    type: "mail.send", config: { box: "ops@example.com", to: "team@example.com",
        subject: "Urgent", text: "{{input.text}}" } },
    { id: "file",     type: "storage.write", config: { storage: "…", action: "insert", collection: "tickets",
        documents: [{ text: "{{input.text}}" }] } },
  ],
  edges: [
    { from: "__trigger", to: "classify" },
    { from: "classify", to: "check" },
    { from: "check", to: "approve", branch: "true" },
    { from: "check", to: "file",    branch: "false" },
    { from: "approve", to: "alert" },
  ],
});
```

## 保存前检查了哪些内容 {#validated}

- 每一步ID都是独特的,结构完善;最多有30个。
- 每个步骤类型都存在,而且有其本身所需的配置。
- 每一 `{{steps.…}}` 参考文献引用点指定一个现有步骤 **上 上 层**.
- 图表有精确的边缘 与触发, 没有循环, 也没有无法到达的一步。
- 状况有 `true` 和 a 和 a `false` 边缘; 开关每个大小写加一个 `default`;合并至少有两个输入。
- 账户外的任何行为 `human` 上上下一步 上下一步
- A 音 A `agent.run` 仅指定存在的工具 。

> **最常用的拒绝**
>
> {{steps.draft.output.text校对:Soup

## 代理工具已连序 {#tools}

```javascript
{ id: "research", type: "agent.run", config: {
    model: "gemini-3.5-flash",
    tools: { search: api.tools.search, fetch: api.tools.fetch },   // the SDK serialises this
} }
```

以对象方式写入 。 以 数组方式写入 。 已经以数组方式写入 , 以 原样发送 , 未知的工具名则与 存在 工具 列表 拒绝 。

## 错误 {#errors}

上面的一切 都回到了 `invalid_workflow` (400) 带有一个标出步骤和问题的信息。有一个代码, 因为有一个答案: 固定定义 。

- [工作流定义](/zh/sdk/workflows): 定义是什么,拒绝什么。
- [工作流步骤](/zh/sdk/workflows/steps): 全部 23 种类型。
- [runStep()](/zh/sdk/ref/workflow/run-step): 尝试一步 拯救链。

```python
workflow = api.workflows.create({
    "name": "Triage",
    "trigger": {"type": "manual"},
    "steps": [
        {"id": "classify", "type": "model.generate", "config": {"model": "gemini-3.5-flash",
            "prompt": "Is this urgent? {{input.text}}",
            "schema": {"type": "object", "properties": {"urgent": {"type": "boolean"}}}}},
        {"id": "check", "type": "condition", "config": {"left": "{{steps.classify.output.urgent}}", "operator": "eq", "right": True}},
        {"id": "approve", "type": "human", "config": {"title": "Send the alert?"}},
        {"id": "alert", "type": "mail.send", "config": {"box": "ops@example.com", "to": "team@example.com",
            "subject": "Urgent", "text": "{{input.text}}"}},
        {"id": "file", "type": "storage.write", "config": {"storage": "…", "action": "insert", "collection": "tickets",
            "documents": [{"text": "{{input.text}}"}]}},
    ],
    "edges": [
        {"from": "__trigger", "to": "classify"},
        {"from": "classify", "to": "check"},
        {"from": "check", "to": "approve", "branch": "true"},
        {"from": "check", "to": "file", "branch": "false"},
        {"from": "approve", "to": "alert"},
    ],
})
```

```python
# In Python, an agent.run step names its built-in tools; the server runs them
{"id": "research", "type": "agent.run", "config": {
    "model": "gemini-3.5-flash",
    "tools": ["search", "fetch"],
}}
```
