Skip to content

POST /workflows/:id/runs

定义

为指定工作流启动一次运行。支持异步(立即返回 running)与同步(阻塞至完成或暂停)两种模式。

用途

  • 触发已注册工作流执行
  • 传入初始 input 写入 SharedState(如 task 字段)
  • 集成测试中使用 sync: true 等待结果

方法与路径

项目
方法POST
路径/workflows/:id/runs
Content-Typeapplication/json

路径参数

参数类型必填说明
idstring工作流 ID(metadata.id

请求 Body

字段类型必填默认值说明
inputRecord<string, unknown>{}初始共享状态键值
syncbooleanfalsetrue 时阻塞至完成 / 暂停 / 失败

响应

状态码: 202 Accepted

返回 RunRecord

字段类型说明
runIdstring新运行 ID
workflowIdstring工作流 ID
statusRunStatusrunning / completed / paused / failed(sync 时可能已终态)
createdAtnumber创建时间戳
updatedAtnumber更新时间戳
resultWorkflowResultsync 完成或暂停时存在
errorstringsync 失败时存在
json
{
  "runId": "run-1-1710000000000",
  "workflowId": "yaml-sequential-example",
  "status": "completed",
  "createdAt": 1710000000000,
  "updatedAt": 1710000000500,
  "result": {
    "runId": "run-1-1710000000000",
    "completedUnits": ["research", "write"],
    "state": { "task": "demo", "output.write": "written draft" },
    "messages": [],
    "duration": 120,
    "tokenUsage": 60,
    "cost": 0.002
  }
}

错误

状态码条件Body
500未知工作流或执行异常{ "error": "<message>" }

示例

bash
curl -X POST http://127.0.0.1:8787/workflows/yaml-sequential-example/runs \
  -H "Content-Type: application/json" \
  -d '{"input":{"task":"hello"},"sync":true}'

TypeScript SDK:

typescript
const record = await client.startWorkflow('yaml-sequential-example', { task: 'hello' }, { sync: true });
console.log(record.result?.state['output.write']);

相关

MIT Licensed