第一个工作流
在 agent.json 中添加一个 workflows 映射。每个键是一个工作流的名称;每个值包含一个触发器和若干活动。
{
"workflows": {
"morning-summary": {
"trigger": { "type": "schedule", "cron": "0 8 * * 1-5" },
"description": "Summarize yesterday's open conversations every weekday morning.",
"activities": [
{ "id": "summarize", "intent": "Summarize yesterday's open customer conversations and what each one is waiting on." }
]
}
}
} 这个工作流在工作日的 08:00 运行,按机器人的本地时间计算。员工会以自己的角色设定、技能和连接来执行该活动。
工作流字段
| 字段 | 含义 |
|---|---|
trigger | 必填。工作流何时运行。参见“触发器”。 |
description | 此工作流的用途。 |
activities | 各个步骤。参见“活动”。 |
connections | 由 {from, to, label} 组成的边,使活动构成一张图。__trigger__ 是起点,__emit__ 是终点。 |
emit | 此工作流完成时发布的事件:一个列表,或一个以逗号分隔的字符串。参见“事件”。 |
inputs | 传给每次运行的值。 |
budget | {total_per_run, cost_estimate}。在图运行中,total_per_run 限制输出 token 数;其他情况下两者都只是估计值。 |
case | 让工作流针对每个人或每件事成为一个长期运行的案例。参见“案例”。 |
只有触发器、没有活动的工作流也是有效的。没有活动的 watch 只会把它的事件转给其他工作流。
一次运行如何执行
没有 connections 时,活动按顺序运行,由员工逐一执行。每个活动的结果都会传给下一个。没有输出的活动会结束这次运行。
有 connections 时,活动会构成一张图。各分支并行运行,其中六种活动类型无需模型即可运行:condition、loop、wait、http、command 和 decide。当路由必须精确时,就使用图。
{
"trigger": { "type": "watch", "plugin": "mail", "event": "email.new" },
"activities": [
{ "id": "classify", "type": "decide",
"params": {
"questions": {
"kind": {
"type": "choice",
"instructions": "What kind of message is this?",
"criteria": { "invoice": "A bill from a vendor", "other": "Anything else" }
}
},
"default": { "kind": "other" }
} },
{ "id": "is-invoice", "type": "condition", "params": { "expression": "nodes.classify.kind.choice == invoice" } },
{ "id": "record", "intent": "Record the invoice in _watch_payload as a bill and note the due date." }
],
"connections": [
{ "from": "__trigger__", "to": "classify" },
{ "from": "classify", "to": "is-invoice" },
{ "from": "is-invoice", "to": "record", "label": "True" },
{ "from": "record", "to": "__emit__" }
],
"emit": ["invoice.recorded"]
} 一次运行接收什么
员工始终拥有自己的角色设定,以及所有者对其 inputs 问题的回答。根据触发器的不同,一次运行还会收到以下值。
| 输入 | 出现条件 |
|---|---|
_event_source, _event_payload, _event_origin | event 触发器被触发时。8 KB 及以上的负载会被缩减为其标量字段,但保留邮件头和附件引用。 |
_watch_payload | watch 或 folder 触发器被触发时。监听器输出的一行,或者对文件夹而言是 {files}。 |
inputs | 始终。工作流自己的 inputs 值。 |
案例
有些工作会持续好几天:需要跟进的潜在客户、等待文件的请求。加上 case 后,工作流会为每个人或每件事保持一个未结案例,而不是每次都从头开始。
| 字段 | 含义 |
|---|---|
key | 必填。以逗号分隔、指向触发数据的点路径,用于识别对象,例如 contactEmail,email,phone。 |
type | 案例的类别,例如 lead。类型相同的工作流共享案例。默认为工作流名称。 |
default_wait | 当某一轮没有指定等待时间时要等待多久:3d、12h、45m。默认三天。 |
案例的每一轮都必须以一个 JSON 对象结束,之后不能再有任何内容。result 是业务状态;next 告诉引擎是 wait 还是 close。截止时间使用 RFC 3339 格式或相对时长。其他任何形式都是无效的一轮。
{"result": {"status": "awaiting_documents", "summary": "Requested two bank statements"},
"next": {"action": "wait", "on": "signal", "deadline": "3d", "reason": "documents"}} 限制与恢复
- 每个活动最多可进行 50 轮模型交互,除非
params.maxIterations另有规定。 - 在图中,一个活动在一次运行里最多可运行 10,000 次。
- 达到所有者为该员工设定的支出上限时,运行会停止。活动的
token_budget只是估计值。 - 因重启而中断的运行会被标记为已中断,并恢复一次。
- 员工可以用
exit工具提前结束运行。
运行和管理工作流
所有者可以手动运行任何工作流。员工通过 run_workflow、workflow_status、list_workflow_runs、set_workflow_enabled 以及助手与团队中列出的其他工作流工具来管理工作流。