跳到主要内容

limits 与能力治理

Agent 流程跑飞的三种方式:并发打爆、调用次数失控、越权读写。 Agent Flow 把三件事都做成语言结构。

limits:预算

limits {
concurrency: 4 // 并发 agent 调用上限
agent_runs: 45 // 整个 workflow 的 agent 调用总次数上限
duration: 30m // 墙钟上限
}
  • 值必须为正(invalid-limits);字段不可重复
  • 最终生效 = host 策略 ∩ workflow limits 的较小者——宿主还能再紧
  • 超限行为:agent_runsLimitExceededError;durationWorkflowTimeoutError;外部取消 → FlowCancelledError

怎么估 agent_runs:数调用点。一个 parallel map 上界是 输入条目上界 × 1(修复回路不占 runs 预算的额外次数,但重试算新调用? 不——重试也计),再加非 map 的固定调用。宁紧勿松:超限是快速失败, 好过账单爆炸。

重试与预算

retry 的每次执行同样经过并发闸与预算检查;agent_runs 统计的是 实际执行次数,含重试。

tools:请求工具能力

tools none // 请求空集
tools [read_file, grep] // 请求若干(逗号必需,可尾随)

tools 列表是请求;生效集合 = 请求 ∩ host policy.allowedTools。 宿主策略是天花板:请求了 write_file 而策略不允许,就拿不到。

实践原则:按最小必要声明。只读阶段(分析、分类)给 [read_file, grep, list_dir];写阶段才加 write_file/edit_file; 纯推理(汇总、写作)用 tools none

write:声明写入范围

write item.writes // 条目自带的 path[] 字段(delivery 模式)
write input.write_scope // 入参声明的 path[](kb-audit 模式)
  • 表达式静态类型必须为 path[];同类型数组字面量会精确推断元素类型
  • 写范围同样与宿主策略求交;越界写入被策略拦截

两个惯用模式,取自真实示例:

// 模式一:每个工作包自带写范围,并要求互不相交
type WorkItem { id: text, owner: member<crew>, writes: path[] }
require disjoint(work[*].writes) else fail "write scopes must not overlap"
...
write item.writes

// 模式二:workflow 级写范围
type KbAuditRequest { kb_path: path, write_scope: path[], articles: ArticleRef[] }
...
write input.write_scope

member<Team>:人的成员资格

use team "delivery-team" as crew

type WorkItem { id: text, owner: member<crew>, writes: path[] }

member<crew> 的值是该团队的成员 id。它出现在两个位置:

  1. 类型位置(如上):Schemax-flow-member 标注
  2. 调用位置:agent(crew.member(item.owner)) —— Runtime 校验 item.owner 确实是 delivery-team 的成员,否则 CapabilityViolationError

"把任务派给真实存在的人"由运行时保证,拼错人名的 workflow 在第一次 路由时就失败,而不是静默派给空气。

use:资源是逻辑的

use team "engineering-team" as engineering
use agent "secure-code-reviewer" as security

字符串 id 不指向任何厂商产品;运行时由 AgentRuntime.resolveAgent/resolveTeam 解析。别名在 workflow 内唯一 (duplicate-alias)。

治理全景

关注点结构保证者
并发limits.concurrency + map limit宿主 semaphore
调用次数limits.agent_runsRuntime 计数
时间limits.duration + 每 agent timeoutAbortSignal 竞速
工具tools [...] ∩ policy宿主收窄
写范围write path[] ∩ policy宿主策略
人员member<Team> 资格校验Runtime
执行边界沙箱 isolate,唯一出口 $host.invoke沙箱

下一步