Building an Agent Tool for User Questions
A tutorial explains how to implement an askQuestion tool that pauses an agent, sends a question to the user, receives the answer as a tool result, and resumes execution. It covers tool schema design, serialized interrupt-and-resume state, rules for deciding when to ask, timeout and fallback handling, and approaches in LangGraph, OpenAI Agents SDK, Agno, and AgentScope. A runnable Python example uses predefined answers and no third-party libraries to demonstrate the full question-to-answer loop.
The tutorial provides a concrete implementation pattern for human-in-the-loop agents. The report identifies missing information, consequential decisions, and high-risk actions as cases where asking a user can prevent unsupported assumptions or unreviewed actions.
核心结论:给 Agent 加「向用户提问」的能力,本质是加一个特殊工具——当 Agent 调用它时,执行不是「返回结果」,而是「暂停」(interrupt),把问题抛给用户,等用户回答后把答案当成工具结果(tool result)回填,再继续跑(resume)。这就是 human-in-the-loop(人在回路)的核心机制。落地要解决四件事:① 设计工具的 Schema(问题、选项、单选/多选、是否允许自定义输入);② 实现「工具调用 → 中断 → 序列化状态 → 用户输入 → 恢复」的完整链路;③ 定好「什么时候该问」的规则(别问太泛、别问太频);④ 处理超时和中断兜底。做对了,Agent 从「瞎猜」变成「先确认再动手」,成功率会明显提升——因为很多失败不是能力不够,是信息不足还硬猜。