顶层结构与管道
一个 .flow 文件必须包含至少一个 workflow。本页讲一个 workflow 的骨架:
声明、资源、限制、类型、管道与阶段。
workflow 声明
workflow deliver_change(input: ChangeRequest) -> Delivery {
// use / limits / type / pipeline,顺序任意
pipeline delivery {
return { changes: [], review: { approved: true } }
}
}
- 形参必须命名为
input,且只有一个(错误码workflow-param-name) - 输出类型在
->之后:编译期检查 pipeline 返回值(workflow-return-mismatch), 运行时再按 Schema 校验一次 limits与pipeline至多各一个;pipeline必须存在
use:声明资源
use team "engineering-team" as engineering
use agent "secure-code-reviewer" as security
use 只声明逻辑资源——字符串是资源 id,不指向任何具体产品。
真正的解析发生在运行时(AgentRuntime.resolveAgent/resolveTeam),
别名在 workflow 作用域内唯一。
limits:预算与上限
limits {
concurrency: 4 // 并发 agent 调用上限(正整数)
agent_runs: 12 // 整个 workflow 的 agent 调用总次数上限
duration: 30m // 墙钟时长上限(时长字面量)
}
三个字 段均可选;最终生效值为 host 策略 ∩ workflow limits 的较小者。
agent_runs 超限抛 LimitExceededError,duration 超限抛 WorkflowTimeoutError。
type:结构化类型
type WorkItem {
id: text
owner: member<engineering>
writes: path[]
acceptance: text[]
}
type Plan {
summary: text
work: WorkItem[1..6] // 数组,最少 1 个最多 6 个
}
类型声明顺序任意、允许前向引用,但不允许递归。详细规则见 类型系统。
pipeline 与 stage
pipeline 是语句的容器;stage 是具名的阶段,名字即结果变量:
pipeline delivery {
stage plan -> Plan {
let result = agent(engineering.main) { /* ... */ expect Plan }
require result.work.count in 1..6 else fail "..."
return result
}
// ↓ 显式依赖声明
stage execute after plan -> ChangeResult[] {
// plan 在这里可见
return parallel map plan.work as item { /* ... */ }
}
stage review after execute -> ReviewResult { /* ... */ }
return { changes: execute, review: review } // 最后一句话必须是 return
}