Confirmation Tool
Confirmation Tool 是一种特殊工具,让 Agent 在执行高风险操作前请求用户确认。它是 Human-in-the-loop 的工具化实现。
#type / concept
#status / evergreen
#tech / ai
[!info] related notes
Confirmation Tool
一句话定义
Confirmation Tool 是一种特殊工具,让 Agent 在执行高风险操作前请求用户确认。它把”需要审批”这件事变成了一个标准的工具调用流程。
核心原理
与 Permission Boundary 的区别
| Permission Boundary | Confirmation Tool | |
|---|---|---|
| 检查方式 | 自动化规则 | 人类判断 |
| 适用场景 | 明确的权限规则 | 需要人类判断的场景 |
| 实现 | 代码检查 | 工具调用中断 |
Python 实现
confirmation_tool = Tool(
name="confirm_action",
description="在执行高风险操作前请求用户确认。执行任何删除、修改、发送操作前都应该调用此工具。",
parameters={
"type": "object",
"properties": {
"action": {"type": "string", "description": "要执行的操作"},
"details": {"type": "string", "description": "操作详情"},
"risk_level": {"type": "string", "enum": ["low", "medium", "high"]},
},
"required": ["action"]
},
handler=confirmation_handler,
)
async def confirmation_handler(action: str, details: str = "", risk_level: str = "medium"):
# 返回 interrupt 事件,暂停 Agent 执行
return InterruptRequest(
type="approval_required",
message=f"即将执行: {action}",
details=details,
risk_level=risk_level,
)
常见坑
- 确认太多: 每个操作都要确认,用户体验差
- 确认太少: 高风险操作没有确认
- 确认信息不足: 用户看不到操作详情