第一個工作流程
在 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 | 讓工作流程針對每個人或每件事,形成一個長期進行的案件。請參閱「案件」。 |
有觸發條件但沒有活動的工作流程也是有效的。沒有活動的監看只會把它的事件轉送給其他工作流程。
執行的方式
沒有 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 | 事件觸發條件啟動時。8 KB 以上的承載資料會縮減為其純量欄位,但保留電子郵件標頭與附件參照。 |
_watch_payload | 監看或資料夾觸發條件啟動時。監看程式輸出的一行內容,或資料夾的 {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"}} 限制與復原
- 除非
params.maxIterations另有設定,否則每個活動最多可使用 50 個模型回合。 - 在圖形中,一個活動在單次執行中最多可執行 10,000 次。
- 擁有者為員工設定的支出上限一旦達到,就會停止執行。活動的
token_budget只是估計值。 - 因重新啟動而中斷的執行會被標示為已中斷,並恢復執行一次。
- 員工可以用
exit工具提前結束執行。
執行與管理工作流程
擁有者可以手動執行任何工作流程。員工透過 run_workflow、workflow_status、list_workflow_runs、set_workflow_enabled,以及 助手與團隊中列出的其他工作流程工具來管理工作流程。