AI 工具调用中的人类参与(Human-in-the-loop for AI tool calls)#
在 AI 代理执行特定工具之前,你可以要求人工审批。当工具需要人工审核时,工作流程会暂停,等待人员执行以下操作之一:
🌐 You can require human approval before an AI Agent executes a specific tool. When a tool requires human review, the workflow pauses and waits for a person to take one of the following actions:
- 批准:该工具根据 AI 指定的输入执行操作。
- 拒绝:该操作已取消且不会执行。
此功能允许对 AI 工作流程中的工具使用进行选择性监督,从而更容易对高风险工具(例如发送消息、修改记录或删除数据)进行额外审查。
🌐 This feature allows for selective oversight of tool use within AI workflows, making it easier to apply additional review to tools with higher risk, such as sending messages, modifying records, or deleting data.
何时使用人工审核(When to use human review)#
当需要以下情况时,人机循环(HITL)审查是有用的:
🌐 Human-in-the-loop (HITL) review is useful when:
- 工具执行不可逆操作:删除数据、发送外部通信或进行购买。
- 存在合规要求:受监管的行业可能要求对某些自动化操作进行人工审批。
- 涉及高价值决策:对业务有重大影响的行动需要人工监督。
- 你正在建立对人工智能工作流程的信任:从启用人工审核开始,随着信心的增加逐步减少监督。
HITL 可以应用于连接到 AI 代理节点的所有工具,也可以仅应用于选定的单个工具,比一般的输出控制提供更精确的控制。
🌐 HITL can be applied to all tools connected to an AI Agent node, or just selected individual tools, offering more precise control than general output gating.
怎么运行的(How it works)#
- AI代理确定它需要使用启用了人工审核的工具。
- 工作流程会暂停,并通过你配置的渠道(例如 Slack、Telegram 或 n8n 聊天界面)发送审批请求。
- 人工审核员会收到请求,显示 AI 想要使用的工具以及所使用的参数。
- 审核员要么批准请求,要么拒绝请求。
- 如果获批,该工具将使用 AI 指定的输入执行操作。如果被拒绝,该操作将取消,并通知 AI 已被拒绝。
不同的审批渠道
审查步骤可以通过与主要交互不同的渠道进行。例如,你可以让用户通过 n8n 聊天界面与 AI 代理互动,但将审批请求发送给 Slack 中的特定人员。
为工具设置人工审核(Setting up human review for tools)#
步骤 1:打开工具面板(Step 1: Open the Tools Panel)#
在你的工作流中,点击 AI 代理节点上的 工具 连接器以打开工具面板。
🌐 In your workflow, click the Tools connector on an AI Agent node to open the Tools Panel.
步骤2:添加人工审核环节(Step 2: Add a human review step)#
- 在工具面板中,找到人工审核部分。
- 从可用选项中选择你首选的审批渠道。
- 使用适当的凭据和设置配置审批通道。
步骤3:将工具连接到评审步骤(Step 3: Connect tools to the review step)#
- 将需要批准的工具添加到人工审核步骤的工具连接器中。
- 像平常一样配置每个工具。
可用审批渠道(Available approval channels)#
您可以使用以下任何服务作为您的人工审核渠道:
🌐 You can use any of the following services as your human review channel:
| 渠道 | 描述 |
|---|---|
| 聊天 | n8n 内置的聊天界面 |
| Slack | 将审批请求发送到 Slack 频道或私信 |
| Discord | 将审批请求发送到 Discord 频道 |
| Telegram | 通过 Telegram 发送审批请求 |
| 微软 Teams | 将审批请求发送到 Teams 频道或聊天 |
| Gmail | 通过电子邮件发送审批请求 |
| WhatsApp 企业云 | 通过 WhatsApp 发送审批请求 |
| Google 聊天 | 将审批请求发送到 Google 聊天 |
| 微软 Outlook | 通过 Outlook 邮件发送审批请求 |
在人工审核工具中使用表达式(Using expressions in human review tools)#
$tool 变量(The $tool variable)#
在配置人工审核步骤时,你可以使用 $tool 变量来为审核员构建消息,以提供有关 AI 正在尝试执行的操作的上下文。该变量有两个属性:
🌐 When configuring the human review step, you can use the $tool variable to construct a message for the reviewer that provides context about what the AI is trying to do. This variable has two properties:
| 属性 | 描述 |
|---|---|
$tool.name |
AI 代理尝试调用的工具名称。这是 n8n 画布上显示的节点名称。 |
$tool.parameters |
AI 代理在工具调用中尝试使用的参数。这包括在工具输入模式中任何配置了 $fromAI() 表达式的字段。 |
示例消息配置:
1 2 | |
这有助于审核人员在批准或拒绝请求之前,准确了解 AI 正在尝试的操作。
🌐 This helps reviewers understand exactly what action the AI is attempting before they approve or deny the request.
在人类审核工具中使用 $fromAI()(Using $fromAI() in human review tools)#
$fromAI() 函数 可与连接到人工审核步骤的工具一起使用。这意味着 AI 可以动态指定工具参数,而这些由 AI 决定的值就是人工审核者看到并批准的内容。
🌐 The $fromAI() function works with tools connected to human review steps. This means the AI can dynamically specify tool parameters, and those AI-determined values are what the human reviewer sees and approves.
系统提示最佳实践(System prompt best practices)#
为了让 AI 代理正确解读并处理被拒绝的工具调用尝试,请在系统提示中包含有关人工审核设置的信息。
🌐 For the AI Agent to correctly interpret and handle denied tool call attempts, include information about the human review setup in your system prompt.
需要系统提示配置
请确保在系统提示中包含工具设置和人工审核步骤。这有助于 AI 理解哪些工具需要审批,以及在工具调用被拒绝时如何得体地回应。
考虑包括:
🌐 Consider including:
- 哪些工具需要人工批准
- 当批准被拒绝时会发生什么
- AI 应该如何应对拒绝(例如,通知用户、提出替代方案或请求澄清)
链式调用与子代理(Chaining and subagents)#
当将 AI 代理作为另一个 AI 代理的工具使用时,子代理中的人工审查步骤能正常工作。
🌐 When using an AI Agent as a tool for another AI Agent, human review steps in the subagent work correctly.