在构建需要多轮思考、工具调用和外部交互的智能体时,往往会出现「执行到一半」才发现上下文不完整或风险未知的情况。新一代 LLM 越来越强调 主动修正计划、提出澄清问题并寻求确认,这为我们提供了在关键节点让 Agent 主动停下来、等待人工介入的设计思路。
这些操作一旦完成即产生副作用,错误往往只能通过补救流程处理。因此在系统提示词或工作流中必须加入 硬确认(如 await_user_confirmation())并在 UI 层提供明确的“确认”或“取消”按钮。
await_user_confirmation()
对于 查询、检索、数据预处理、工具调用的参数构造 等可重复的步骤,智能体只需要一次澄清即可继续。例如:
这些节点的确认可以采用 软确认(仅提示用户输入或选择),不需要阻断整个工作流,只要得到明确答案即可继续执行后续步骤。
下面示例展示了如何在 系统提示词(system prompt)里声明两类确认机制。关键是把「何时需要确认」的判断逻辑写成可复用的指令块,而不是让模型自行猜测。
You are an autonomous agent tasked with a multi‑step workflow. When you reach a step that involves any of the following actions, you must stop and request explicit user confirmation before proceeding: - Writing to persistent storage (database, file, cloud bucket) - Sending external communications (email, SMS, webhook) - Initiating a financial transaction (payment, refund, transfer) - Triggering a core business process (order creation, inventory deduction) For all other steps, if you encounter ambiguous input or missing parameters, ask a clarification question and resume automatically after the user answers.
在实际实现时,可将上述指令块保存为变量 CONFIRM_RULES,并在每次生成下一步指令前先检查当前动作是否匹配列表,从而决定调用 await_user_confirmation() 还是 ask_for_clarification()。
CONFIRM_RULES
ask_for_clarification()
下面以 LangGraph 为例,展示如何在工作流图中标记硬确认与软澄清节点。图中红框表示必须人工硬确认,蓝框表示仅需一次澄清。
from langgraph import Graph graph = Graph() @graph.node def fetch_data(state): # 可能出现搜索关键词不明确的情况 if not state.get("keyword"): return ask_for_clarification("请提供要搜索的关键词") return search(state["keyword"]) @graph.node def write_to_db(state): # 必须硬确认 return await_user_confirmation( f"即将把以下数据写入数据库:{state['result']}n确认吗?" ) @graph.node def send_email(state): # 必须硬确认 return await_user_confirmation( f"准备发送邮件给 {state['recipient']},主题为 “{state['subject']}”。确认发送?" ) graph.add_edge(fetch_data, write_to_db) graph.add_edge(write_to_db, send_email)
通过上述方式,开发者可以在 系统提示词 与 工作流节点 两层同时控制确认逻辑,既保证关键操作的安全,又不影响整体效率。
await_user_confirmation
ask_for_clarification
把这些步骤套用到自己的业务流程后,就能得到一套 可复用的停点划分方法:关键的不可逆节点必须硬确认,信息不足的可回退节点只需一次澄清。这样既保障了安全,又保持了智能体的高效运行。
Δ
Ctrl+D