Skip to content

feat: add Clarification tool and UI#701

Open
Bl3f wants to merge 2 commits intomainfrom
cursor/add-clarification-tool-5838
Open

feat: add Clarification tool and UI#701
Bl3f wants to merge 2 commits intomainfrom
cursor/add-clarification-tool-5838

Conversation

@Bl3f
Copy link
Copy Markdown
Contributor

@Bl3f Bl3f commented Apr 30, 2026

Summary

Adds a new clarification agent tool + UI, mirroring the SOTA behaviour in Claude Code and Codex. When the user's request is genuinely ambiguous (multiple plausible tables, unclear metric, missing time range, etc.), the agent can call this tool to ask one focused question and optionally surface 2–5 clickable answer chips. The agent then stops and waits for the user's reply.

UX

  • Clicking an option chip sends the answer directly — no extra Enter press required.
  • Free-form answers are still supported via the normal chat input.
  • Multi-turn clarification works naturally: every new user message ends the current clarification turn. The agent can call clarification again on the next turn; previous cards automatically switch to an "Answered" state (muted, checkmark on the selected chip) so the user keeps the full decision trail visible.
  • Intermediate answers don't need dedicated storage: they live as ordinary user messages in the chat history, and the model reads them back on every subsequent step. The tool call itself is preserved too (not pruned like suggest_follow_ups), so the assistant remembers what it asked.

Walkthrough

Direct-send + multi-turn answered state:

clarification_v2_direct_send_and_answered_state.mp4

Initial clarification card with chips:

Clarification card with Quick question header and option chips

Clicking a chip sends it instantly (input stays empty, message appears as a user bubble):

Chip click sends directly

When a follow-up clarification fires, the previous card turns into an "Answered" card with a checkmark on the selected option:

Multi-turn state: previous card marked answered

What changed

  • Shared schema (apps/shared/src/tools/clarification.ts) — zod input { question, options?: string[2..5] }.
  • Backend tool (apps/backend/src/agents/tools/clarification.ts) — registered in tools/index.ts; the ToolLoopAgent's stopWhen now also fires on clarification so the run halts and waits for the user.
  • System prompt + tool description — describe when to use it (only when guessing would be costly, never alongside other tools or suggest_follow_ups), and now explicitly cover the multi-turn flow: one question per call, ask the next on a later turn, never re-ask something already answered.
  • Frontend — new ClarificationToolCall component (apps/frontend/src/components/tool-calls/clarification.tsx):
    • renders a "Quick question" card with the question and pill-shaped option chips;
    • chip click dispatches queueOrSendMessage({ text: option }) from the agent context for immediate submission;
    • detects whether a user message has been sent after this tool call and, if so, renders the card in an "Answered" muted style with a checkmark on the matching option (so stale cards remain informative but non-interactive);
    • added to NON_COLLAPSIBLE_TOOLS so it never gets folded into a tool group.
  • Messaging providerstool-clarification added to EXCLUDED_TOOLS so Slack/Telegram/etc. summaries don't render raw tool entries for it.

Testing

  • npm run lint
  • ✅ Manual end-to-end in the live app (see walkthrough): agent calls the tool, chip click sends instantly, follow-up clarification renders, previous card marked answered with checkmark.
  • ⚠️ npm run -w @nao/backend test — 11 pre-existing failures on main (system-prompt date tests, sqlite tests, compaction LLM); none related to this change.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Adds a new `clarification` agent tool that lets the model ask the user
a focused question when the request is ambiguous (multiple plausible
tables, unclear metric, etc.), mirroring the SOTA behaviour in Claude
Code and Codex.

- Shared zod schema (question + optional 2-5 options) in
  `apps/shared/src/tools/clarification.ts`.
- Backend tool registered in `agents/tools`; the ToolLoopAgent stops
  when the tool is called so the user can reply.
- System prompt instructs when to call the tool (only when guessing
  would be costly, never alongside other tools or suggest_follow_ups).
- Frontend `ClarificationToolCall` renders a card with the question
  and clickable option chips that populate the chat input. Marked
  non-collapsible so it never gets folded into a tool group.
- Clarification tool calls are excluded from messaging provider
  summaries.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

🚀 Preview Deployment

URL https://pr-701-5fcaa26.preview.getnao.io
Commit 5fcaa26

⚠️ No LLM API keys configured - you'll see the API key setup flow when trying to chat.


Preview will be automatically removed when this PR is closed.

- Clicking an option chip now sends the answer directly via
  queueOrSendMessage instead of only filling the prompt.
- Each clarification tool call now detects whether a user message
  has come in after it in the conversation. If so, it switches to
  an "Answered" state: chips are disabled and the selected option
  gets a checkmark and secondary style. This naturally supports
  multi-turn / multiple clarification questions — older cards
  remain visible as answered context.
- Strengthened the system prompt + tool description to clarify the
  multi-turn flow (one question per call, ask the next on a later
  turn, never re-ask something already answered).
@Bl3f Bl3f marked this pull request as ready for review April 30, 2026 16:25
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 10 files

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants