Repository navigation
Description
Is there an existing feature request for this?
- I have searched existing issues and feature requests, and this is not a duplicate.
Problem or Use Case
When the agent hits genuine ambiguity mid-task it has no structured way to ask the
user. It either guesses — risking wasted work — or drops the question into a chat
message, which does not pause execution and offers no clear choices. This is the
top gap in the Claude Code parity tracker (#2055).
Concrete cases:
- Architecture decisions the code does not encode. "Add authentication to
this API" — session, JWT, or OAuth? Each cascades into schema, middleware, and
frontend. Today the agent picks one and hopes. - Destructive migrations with several valid paths. "Migrate class components
to hooks" — all at once, incrementally by directory, or simple-first? - Product decisions. "Create a user settings page" —
/settingsvs
/accountvs/preferences, which sections? These cannot be inferred.
Desired Behavior
A first-class SDK tool, ask_user, that lets the agent pause mid-task and ask one
or more structured questions in a single call. Each question has 2–4 labelled
options (each with a description), single- or multi-select, and an
always-available "Other" free-text escape hatch. The call ends the current run
at a waiting status; the user's answer resumes the run and becomes the tool
observation (the same pause/resume shape as confirmation mode — not a
fire-and-forget call).
This issue is the first, self-contained slice and adds no new Agent Server
endpoint or event type: the answer arrives through the existing
send_message() path as a MessageEvent(source="user"), which the SDK matches to
the single pending ask_user request and converts into the tool observation on
resume. The dedicated request/response event pair + endpoint is split into a
follow-up issue (#5566).
Mechanism
The earlier draft said answers arrive "through the UserMessageEvent path". That
type does not exist (user messages are MessageEvent(source="user")), and a tool
cannot simply block on the run-loop thread, which holds the conversation state
FIFOLock across agent.step(). The concrete, deadlock-free mechanism is option
(b) — the confirmation-style pause/resume, not a blocking tool:
- Where the answer enters (Q1). The
ask_usertool validates its arguments,
records one pending request (a generatedrequest_idplus the questions) in
the conversation state, and the run ends atWAITING_FOR_CONFIRMATION(the
existing "run yielded control to the user, resume on input" status — reused to
avoid a new serialized status value in this slice). The answering client calls
send_message()with the structured answer; the SDK detects the single pending
ask_userrequest, converts thatMessageEvent(source="user")into the tool's
observation instead of a normal user turn, and the client resumes the run.
So the answer is a user message — the wording "not as a separate later
message" is dropped; the distinction is that it is consumed as the tool result
for the pending call, not appended as an unrelated turn. - Parsing / validation contract (Q2). Because there is no dedicated transport
in this slice, the structured answer is carried in the user message and matched
by therequest_idrecorded in the pending request. The SDK validates: the
message parses as an answer object, itsrequest_idmatches the one pending
request, and each answer references a question/option that exists. A malformed,
mis-keyed, or stale answer produces a corrective observation ("no pending
ask_user request" / "unrecognized option id …") and does not resolve the call.
The typedrequest_idand the dedicated request/response pair land in [Feature]: Dedicated ask_user request/response event pair and endpoint #5566. - Non-interactive runs (Q3). There is no
interactivecapability flag, and
tool availability is process-global, so this slice cannot define a flag. The
non-interactive criterion is deferred: for now the tool simply is not offered
in headless/eval runs by not registering it there (a follow-up adds the
capability flag and the prompt section; [Feature]: Dedicated ask_user request/response event pair and endpoint #5566 owns the timeout →cancelpath
so a pending request always unblocks).
Why this cannot be a Canvas-only / client-tool feature
Agent Canvas already registers client tools via ClientToolSpec
(openhands/sdk/tool/client_tool.py), used today for canvas_ui_control and
launch_child_conversation. It is tempting to implement the dialog there — but
client tools are fire-and-forget and cannot carry a result back:
ClientToolExecutor.__call__ returns an inline
ClientToolObservation.from_text(text="Tool call dispatched to client."); the real
execution happens client-side and the agent loop continues as if the tool had
completed. ClientToolSpec is {name, description, parameters, annotations} with
no representation of a return value. So a client-tool dialog can show the
question, but the choice has no channel back as the tool result.
Conclusion: the primitive belongs in the SDK. Canvas then consumes it.
Acceptance Criteria
-
ask_useris a first-class SDK tool whose action carries
questions: list[QuestionInfo], each with aheader(short label), 2–4
options(stableid,label,description), and amultiSelectflag. - The call ends the run at
WAITING_FOR_CONFIRMATIONwith one pendingask_user
request recorded; the user's answer resumes the run and becomes the tool
observation (consumed as the tool result, not appended as an unrelated turn). - The answering contract keys answers by a stable option id (the
label
is carried alongside for display), matched to the pending request by its
request_id; the free-text "Other" value is carried with a sentinel/null
option id. -
decline(user said stop asking) andcancel(dismissed) are
distinguishable from an answer in the observation. - Invalid calls (0 questions, >4 options, missing labels, duplicate
ids/labels) return a corrective observation so the agent can fix the call,
not a crash. - A malformed, mis-keyed, or stale answer (no matching pending request, or an
unknown option id) produces a corrective observation and does not resolve the
call. - Non-interactive handling is deferred in this slice: the tool is simply
not registered in headless/eval runs (theinteractivecapability flag and
the timeout →cancelpath land in [Feature]: Dedicated ask_user request/response event pair and endpoint #5566). - Unit tests cover the schema validation, the pause/resume answer path, and the
accept/decline/cancel+ free-text cases.
Alternatives Considered
- Implement it purely in Agent Canvas as a client tool. Rejected: client tools
are fire-and-forget and cannot return a result (see above). - Prompt the agent to ask in prose. Today's behaviour: does not block, offers
no structured choices. - MCP Elicitation only. Elicitation is server-initiated; this feature is
agent-initiated. Adopt its three-action shape later, but do not block this slice
on it (elicitation is currently a decline-only stub in the ACP bridge).
Priority / Severity
High - Significant impact on productivity
Estimated Scope
Medium - New feature with moderate complexity
Feature Area
- Agent API / Core functionality
- Tools / Tool system
- Skills / Plugins
- Agent Server
- Workspace management
- Configuration / Settings
- Examples / Templates
- Documentation
- Testing / Development tools
- Performance / Optimization
- Integrations (GitHub, APIs, etc.)
- Other
Technical Implementation Ideas (Optional)
- Tool name
ask_user(lowercase snake_case, matchingfinish,task_tracker,
ask_oracle,vision_inspect). - Action:
questions: list[QuestionInfo].QuestionInfo:
{question, header (<=12 chars), options: list[{id, label, description}] (2–4), multiSelect: bool}. - Observation: the answers keyed by question, each answer
{option_id|null, label}; plusactioninaccept/decline/cancel. - The agent loop must treat this call as a pause, not the fire-and-forget
client-tool path: record the pending request, end the run at
WAITING_FOR_CONFIRMATION, and convert the matchingsend_message()answer into
the tool observation on resume. - Server-side validation rejects malformed calls with a corrective observation.
Additional Context
Split and follow-up
- This issue (PR 1): the SDK tool + action/observation, using the confirmation
pause/resume shape (the answer arrives viasend_message()as a
MessageEvent(source="user")and is converted to the tool observation). No new
endpoint, no new event type. - Follow-up (PR 2, issue [Feature]: Dedicated ask_user request/response event pair and endpoint #5566): a dedicated
ask_userrequest/response
event pair + endpoint on the Agent Server, elicitation-aligned
(accept/decline/cancel), plus a typedrequest_idso a stale or replayed
answer matches exactly one pending request; and theclients/typescriptmethod.
This is what lets a non-loop client (Agent Canvas) answer deterministically. - Follow-up (PR 3,
OpenHands/OpenHands): the Agent Canvas dialog that renders
the questions and returns the answers.
Prior art / standards
- Claude Code
AskUserQuestion— the reference.
questions[]{question, header(<=12), options[2-4]{label, description}, multiSelect};
"Other" always available. https://code.claude.com/docs/en/agent-sdk/user-input - MCP Elicitation (spec 2025-06-18) —
elicitation/createwithmessage+
requestedSchema; responsesaccept/decline/cancel.
https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation - Other implementations: LangChain deepagents
ask_user(LangGraph interrupts);
Spring AIAskUserQuestionTool; [Feature]: Use Claude Code's native AskUserQuestion tool instead of numbered-option prompts github/spec-kit#2181; Use AskUserQuestion tool on Claude Code for structured user input obra/superpowers#745.
Prior requests (this issue revives them)
- [Tracking] Tools: Missing tool types & dynamic discovery gaps #2041 — "[Tracking] Tools: Missing tool types & dynamic discovery gaps" (closed
not_planned, stale, 2026-07-26). Part of tracker Feature Parity: Bridge Gap with Claude Code Capabilities #2055. - [Feature]: QuestionTool -- let the agent ask the user structured questions mid-task #2697 — "[Feature]: QuestionTool -- let the agent ask the user structured
questions mid-task" (closednot_planned, stale, 2026-09-25). - Historical CLI-only attempts: OpenHands/OpenHands #9392 (issue), #9758 / #9824
(PRs, unmerged). - Related open: [Feature]: Let ACP clients answer permission requests instead of always selecting the first option #5480 (ACP permission requests always auto-select
options[0]; same
"confirmation API is accept/reject only" root cause).
Resolved decisions (revised for this slice)
- Transport: the dedicated
ask_userrequest/response pair is a follow-up;
this slice uses the confirmation pause/resume shape — record a pending request,
end the run atWAITING_FOR_CONFIRMATION, and convert the matching
send_message()answer (MessageEvent(source="user")) into the tool observation. - Scope: split — PR 1 (this issue, tool only), PR 2 (issue [Feature]: Dedicated ask_user request/response event pair and endpoint #5566: transport +
clients/typescript), PR 3 (Canvas dialog). - Answering contract: stable option id (+ label for display); free-text via
sentinel option id; distinctdecline/cancel; arequest_idis recorded now
(to match the answer to the pending request) and formalized as a typed field on
the dedicated pair in [Feature]: Dedicated ask_user request/response event pair and endpoint #5566. - Interactive vs non-interactive: deferred in this slice — the tool is not
registered in headless/eval runs. Theinteractivecapability flag and the
timeout →cancelpath are owned by [Feature]: Dedicated ask_user request/response event pair and endpoint #5566 (no such flag exists onmain, and
tool availability is process-global). - Tool name:
ask_user.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
The request is clear, self-contained, and belongs in this repository: ask_user is an SDK tool / agent-loop change. The issue explicitly scopes the Agent Server transport, timeout handling, TypeScript client, and Agent Canvas dialog to follow-ups (#5566 and OpenHands/OpenHands), so this slice is only the SDK tool plus its pause/resume resolution.
Scope: a first-class SDK ask_user tool whose call pauses the run and is resolved by the next user message, reusing the existing confirmation pause/resume machinery. Explicit non-goals: no new Agent Server endpoint, event type, or serialized status value; no interactive capability flag (tool availability is process-global, so the tool is simply not registered in headless/eval runs); no timeout -> cancel path; no clients/typescript method; no Agent Canvas UI. This slice reuses the existing WAITING_FOR_CONFIRMATION status rather than adding a new serialized one, which keeps persisted-state compatibility out of scope.
Evidence checked against main: ConversationExecutionStatus.WAITING_FOR_CONFIRMATION already exists and LocalConversation._run() breaks when a step leaves that status, then resumes on input - the shape this issue reuses. Client tools (openhands/sdk/tool/client_tool.py) are confirmed fire-and-forget: ClientToolExecutor returns a fixed inline ClientToolObservation, so a client-side dialog cannot return the chosen answer as the tool result. The claims about the MessageEvent(source="user") path and send_message() also hold.
Notes for implementation
- Because the mechanism reuses
WAITING_FOR_CONFIRMATIONand matches the answer byrequest_id, an ordinary user message that does not parse as an answer must fall through to the existing normal user-turn behavior, and must not be consumed as the observation or silently dropped. - The invalid-call corrective observation covers the schema-level errors listed below (0 questions, >4 options, missing labels, duplicate ids/labels). Failures only detectable at runtime (no pending request, unknown option id) are covered by the answering contract.
Acceptance Criteria
-
ask_useris a first-class SDK tool whose action carriesquestions: list[QuestionInfo]; eachQuestionInfohas aquestion, a shortheader, 2-4options(stableid,label,description), and amultiSelectflag, as shown by the tool's exported schema. - Calling
ask_userends the run at execution statusWAITING_FOR_CONFIRMATION(no new serialized status value, no new Agent Server endpoint or event type) and records one pendingask_userrequest carrying a generatedrequest_idand the questions. - A user message sent via
send_message()that parses as a valid answer for the pending request resumes the run and becomes theask_usertool observation; it is consumed as the tool result and is not appended as an unrelated user turn. - The answer contract keys each answer by the stable option id and carries the
labelfor display, matched to the pending request by itsrequest_id; a free-text "Other" value is carried with a sentinel/nulloption id. - The observation distinguishes
accept,decline(user said stop asking), andcancel(dismissed), in addition to the answers. - Invalid calls (0 questions, >4 options, missing labels, duplicate ids/labels) return a corrective observation describing the problem so the agent can fix the call, rather than raising or crashing.
- A malformed, mis-keyed, or stale answer (no matching pending request, or an unknown option id) produces a corrective observation and does not resolve the call; a user message that is not an answer is left to the normal user-turn path.
- Unit tests cover schema validation; the pause/resume path (run ends at
WAITING_FOR_CONFIRMATION, answer viasend_message()becomes the observation on resume); and theaccept/decline/cancelplus free-text ("Other") cases. - A runnable example under
examples/01_standalone_sdk/with amain.pyentrypoint demonstrates the pause/resumeask_userflow end to end and printsEXAMPLE_COST: ..., and is listed intests/examples/test_examples.pyif the examples workflow should run it. - User-facing documentation for the tool describes the pause/resume behavior, and the tool is intentionally not registered in headless/eval runs in this slice.
Activity
leandro-mont commentedon Nov 8, 2026
+1 for this. Here is some field data from a working stopgap, in case it helps shape the tool and the future Canvas dialog.
On Agent Canvas 1.34 I built the same pattern without SDK changes:
It has worked well for a week of daily use with open models (GLM-5.3 and DeepSeek V4.1 Flash through LiteLLM). Lessons that may transfer:
system_message_suffix: "first action on any change request: check for gaps and ask." Theask_usertool description, or a default prompt hint, will likely need a similarly explicit "when to use".The stopgap's limits are exactly what this issue fixes: there is no real pause, it depends on the model emitting valid JSON, and the App has to poll. So a native
ask_userwith a typed request/response pair would be a clear improvement. Happy to test the Canvas dialog when there is a build.