Skip to content

[Feature]: ask_user tool for structured questions #5570

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

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.

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_CONFIRMATION and matches the answer by request_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_user is a first-class SDK tool whose action carries questions: list[QuestionInfo]; each QuestionInfo has a question, a short header, 2-4 options (stable id, label, description), and a multiSelect flag, as shown by the tool's exported schema.
  • Calling ask_user ends the run at execution status WAITING_FOR_CONFIRMATION (no new serialized status value, no new Agent Server endpoint or event type) and records one pending ask_user request carrying a generated request_id and the questions.
  • A user message sent via send_message() that parses as a valid answer for the pending request resumes the run and becomes the ask_user tool 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 label for display, matched to the pending request by its request_id; a free-text "Other" value is carried with a sentinel/null option id.
  • The observation distinguishes accept, decline (user said stop asking), and cancel (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 via send_message() becomes the observation on resume); and the accept/decline/cancel plus free-text ("Other") cases.
  • A runnable example under examples/01_standalone_sdk/ with a main.py entrypoint demonstrates the pause/resume ask_user flow end to end and prints EXAMPLE_COST: ..., and is listed in tests/examples/test_examples.py if 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

  1. added
    ready-for-dev
    on Oct 7, 2026
  2. leandro-mont commented on Nov 8, 2026

    @leandro-mont

    +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:

    • A skill makes the agent end its message with a fenced JSON block (questions, 2–4 options, a suggested option, a multi-select flag).
    • A Canvas Extensions App (v1 routed page) parses that block and renders a picker.
    • The answers go back as a normal user message.

    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:

    1. Triggering mattered more than the UI. In OpenHands only a skill's name and description reach the prompt, so the agent almost never chose to clarify on its own. It went straight into 90+ actions on vague requests. What fixed it was a fixed rule in system_message_suffix: "first action on any change request: check for gaps and ask." The ask_user tool description, or a default prompt hint, will likely need a similarly explicit "when to use".
    2. Batch the questions in one call (we cap at 5) instead of one per turn. Users answer much faster, and it costs fewer LLM round-trips.
    3. Option descriptions should be concrete examples, not abstract labels. "Short: Good morning! Sunny, 24°. 3 events, first at 10am." gets better answers than "Short and varied". This was the biggest quality gain.
    4. Pre-select the recommended option, and treat "decide for me" as a valid answer. Most of the time the user just confirms.
    5. For taste or format questions, also ask for a user example (a before→after, a sample message). We mark these questions with an optional free-text "example" field.
    6. UI that worked:
      • one question per screen, with options stacked vertically (label plus description);
      • "Other" always available, with a text field;
      • Back / Next and a progress bar;
      • a final review screen with "Change" per answer and an optional overall note before sending.
    7. Cost. A clarification turn costs about US$0.03. The guessed implementations it replaced cost over US$1 each to redo.

    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_user with a typed request/response pair would be a clear improvement. Happy to test the Canvas dialog when there is a build.

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

    enhancementready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions