人机协作

wesgine 的 HITL(Human-in-the-Loop)机制允许 Agent 在执行过程中暂停并向用户请求确认或输入。


触发场景

HITL 仅由以下机制触发:

触发源说明
ask_user 工具Agent 主动向用户提问
browser_wait_for_user浏览器自动化安全阀
CycleDetector循环检测第二次 Term 触发 HITL
ErrorStreakDetector连续失败触发 HITL

注意:治理链(Governance)不产生 HITL;HITL 仅用于 Agent 主动交互。


工作流程

Agent 执行中
  │
  ├─ 触发 HITL
  │   ├─ Agent Loop 阻塞
  │   ├─ SSE 事件推送 hitl_request 到前端
  │   └─ 等待用户响应
  │
  └─ 用户响应
      ├─ POST /cells/{id}/hitl/{reqID}/respond
      ├─ Agent Loop 继续
      └─ 超时 → 自动终止

API

GET  /cells/{id}/hitl/pending          待处理请求列表(?run_id=)
POST /cells/{id}/hitl/{reqID}/respond  响应请求

Cell Handle

cell.HITL() → HITLHandle
  .ListPending(ctx, runID)     // 待处理列表
  .Respond(ctx, reqID, resp)   // 响应

CycleDetector 触发

两阶段终止协议中,第二次 CycleTerm 触发 HITL:

  1. 第一次 CycleTerm → 自愈(注入纠正消息 + 重置计数器)
  2. 第二次 CycleTerm → HITL 问用户"怎么办"
  3. HITL 超时 60s → 自动终止 + 保存进度

Actor 边界

HITL 请求属于特定 Run,Run 属于特定 Actor:


browser_wait_for_user

AlwaysOn 安全阀,Cell boot 无条件注册:


反模式

禁止正确做法
治理链触发 HITL治理链只做 Allow/Deny
HITL 外部 HTTP 回调对话内审批
跨 Actor 响应 HITLactor 校验