Skip to content

[Feature]: ask_user tool (structured questions, answers as a user message) #5565

Closed as not planned

Description

@analisaperlengkapan

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:

  1. 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.
  2. Destructive migrations with several valid paths. "Migrate class components
    to hooks" — all at once, incrementally by directory, or simple-first?
  3. Product decisions. "Create a user settings page" — /settings vs
    /account vs /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 (resolved — answers the triage questions)

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:

  1. Where the answer enters (Q1). The ask_user tool validates its arguments,
    records one pending request (a generated request_id plus the questions) in
    the conversation state, and the run ends at WAITING_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_user request, converts that MessageEvent(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.
  2. 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 the request_id recorded in the pending request. The SDK validates: the
    message parses as an answer object, its request_id matches 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 typed request_id and the dedicated request/response pair land in [Feature]: Dedicated ask_user request/response event pair and endpoint #5566.
  3. Non-interactive runs (Q3). There is no interactive capability 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 → cancel path
    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_user is a first-class SDK tool whose action carries
    questions: list[QuestionInfo], each with a header (short label), 2–4
    options (stable id, label, description), and a multiSelect flag.
  • The call ends the run at WAITING_FOR_CONFIRMATION with one pending ask_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) and cancel (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 (the interactive capability flag and
    the timeout → cancel path 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, matching finish, 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}; plus action in accept/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 matching send_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 via send_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_user request/response
    event pair + endpoint on the Agent Server, elicitation-aligned
    (accept/decline/cancel), plus a typed request_id so a stale or replayed
    answer matches exactly one pending request; and the clients/typescript method.
    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

Prior requests (this issue revives them)

Resolved decisions (revised for this slice)

  1. Transport: the dedicated ask_user request/response pair is a follow-up;
    this slice uses the confirmation pause/resume shape — record a pending request,
    end the run at WAITING_FOR_CONFIRMATION, and convert the matching
    send_message() answer (MessageEvent(source="user")) into the tool observation.
  2. 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).
  3. Answering contract: stable option id (+ label for display); free-text via
    sentinel option id; distinct decline/cancel; a request_id is 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.
  4. Interactive vs non-interactive: deferred in this slice — the tool is not
    registered in headless/eval runs. The interactive capability flag and the
    timeout → cancel path are owned by [Feature]: Dedicated ask_user request/response event pair and endpoint #5566 (no such flag exists on main, and
    tool availability is process-global).
  5. Tool name: ask_user.

Full prior art and the original design are on the closed #5506.

Activity

  1. all-hands-bot commented on Oct 7, 2026

    @all-hands-bot
    Collaborator

    The following comments were added by the OpenHands AI agent.

    Decision needed

    This is the bounded first slice of the ask_user feature, and the split from the transport (deferred to #5566) is sound. I verified the surrounding code on main to finalize it, but the load-bearing mechanism for this slice is still described two contradictory ways, so ready-for-dev is withheld until it is settled.

    What I confirmed in the repository:

    • There is no UserMessageEvent type. User messages are MessageEvent(source="user"), emitted by LocalConversation.send_message().
    • run()/arun() hold the conversation state FIFOLock across agent.step(), so tool(action, conversation) executes while that lock is held; a tool called as the sole tool call in a batch runs on the run loop's thread. A tool that blocks waiting for a user message has no defined, deadlock-free unblock path. The only existing "wait for the user" primitive — confirmation mode — ends the run (status WAITING_FOR_CONFIRMATION) instead of continuing to the answer within the step, and no tool returns a value to the agent this way.
    • There is no interactive capability flag anywhere in the SDK or Agent Server, and tool availability (list_usable_tools()) is process-global, not per-conversation.

    The unresolved questions needed to set scope and acceptance criteria:

    1. Within this SDK-only slice, exactly where does the answer enter the agent so the call unblocks and the answers become the tool observation? Target flows:

      • a) a tool executor blocks the calling thread until send_message() provides the answer — if so, which thread must the tool run on (the run-loop thread holds the state lock, and a worker thread must not block the send_message() the answering client needs), and how does the run loop's state lock get released for a blocking tool?; or
      • b) the run ends with a new waiting status, and on resume a detached answer event is converted into the tool observation (the same mechanism as confirmation mode). Which status and which event?
        Please remove the "not as a separate later message" wording if the answer necessarily arrives as a user message.
    2. What is the concrete parsing/validation contract for the answer, given there is no UserMessageEvent? The issue specifies duplicate ids/labels are rejected, but reusing send_message offers no schema and no correlation to a specific pending ask_user call. How is a malformed or stale answer detected and converted to a corrective observation, given there is no request_id in this slice (it is deferred to [Feature]: Dedicated ask_user request/response event pair and endpoint #5566)?

    3. For the "non-interactive" criterion in this slice: what is the source of the interactive capability in an SDK-only change, given the flag does not exist? Is adding a capability field plus a system-prompt section in scope here, or should this criterion be deferred to a follow-up?

    Once these are answered in the issue body, the triage will define the observable criteria (blocking unblock path, answer delivery, accept/decline/cancel + free-text the agent consumes, malformed-call corrective observation, non-interactive behavior) and re-evaluate readiness. Note the boolean at the top of the issue ("answers are delivered through the existing UserMessageEvent path") also needs to name the real event type.

  2. analisaperlengkapan commented on Oct 7, 2026

    @analisaperlengkapan
    ContributorAuthor

    The three questions are now resolved in the body (new "Mechanism (resolved)" section; Acceptance Criteria and Resolved decisions updated).

    1. Where the answer enters — option (b), the confirmation-style pause/resume, not a blocking tool. ask_user records one pending request and the run ends at WAITING_FOR_CONFIRMATION; the answering client calls send_message(), and the SDK converts that MessageEvent(source="user") into the tool observation, then the client resumes. The answer is a user message, so the "not as a separate later message" wording is dropped. (The "UserMessageEvent path" wording was wrong — that type does not exist.)
    2. Parsing/validation — the answer is matched to the pending request by a recorded request_id; malformed/mis-keyed/stale answers produce a corrective observation and do not resolve the call. The typed field on a dedicated pair lands in [Feature]: Dedicated ask_user request/response event pair and endpoint #5566.
    3. Non-interactive — deferred in this slice (no interactive flag exists; tool availability is process-global). The tool is simply not registered in headless/eval runs; the flag and the timeout → cancel path are owned by [Feature]: Dedicated ask_user request/response event pair and endpoint #5566.

    This comment was created by an AI agent (OpenHands) on behalf of @analisaperlengkapan.

  3. analisaperlengkapan commented on Oct 7, 2026

    @analisaperlengkapan
    ContributorAuthor

    Closing to refile through the web issue form.

    The triage automation marked this issue decision_needed and, per its own
    contract, is only invoked when an issue is opened (or via a label/mention event).
    Resolving the questions by editing the body and replying in-thread does not
    re-invoke it, so it has not re-evaluated the issue — it is still without
    ready-for-dev after the decisions were recorded. Refiling through the form so the
    triage automation runs on creation.

    The scope and the recorded decisions are unchanged; they are carried verbatim into
    the refile.

    This comment was created by an AI agent (OpenHands) on behalf of @analisaperlengkapan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions