[PR #5577] [MERGED] Agent Skill: User Survey #5488

Closed
opened 2026-06-05 15:21:31 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5577
Author: @angelplusultra
Created: 5/4/2026
Status: Merged
Merged: 5/21/2026
Merged by: @timothycarambat

Base: masterHead: feat-agent-clarifying-questions


📝 Commits (10+)

  • 8955b69 initialize feature
  • 93128e1 lint
  • de075c2 fix stale comment
  • c05ec96 fix number input
  • ba3615f remove needless condition
  • ebbed65 add survey persistence
  • d2408d4 add clarifying uestions buffer to aibitat instance with helper methods
  • af0ce41 move plugin specific config data away from aibitat instance and into plugin itself
  • 4b0295d create useTimeoutProgress hook
  • 3ef523d ui refactor

📊 Changes

52 files changed (+2429 additions, -205 deletions)

View changed files

frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/ChoiceForm.jsx (+169 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/Footer.jsx (+93 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/Header.jsx (+97 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/InputForm.jsx (+66 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/SurveyBody.jsx (+82 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/index.jsx (+273 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/utils.js (+61 -0)
frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/HistoricalClarifyingQuestions/index.jsx (+35 -0)
📝 frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/index.jsx (+6 -1)
📝 frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ToolApprovalRequest/index.jsx (+7 -24)
📝 frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx (+16 -0)
📝 frontend/src/components/WorkspaceChat/ChatContainer/index.jsx (+4 -8)
frontend/src/hooks/useTimeoutProgress.js (+47 -0)
📝 frontend/src/locales/ar/common.js (+26 -0)
📝 frontend/src/locales/ca/common.js (+26 -0)
📝 frontend/src/locales/cs/common.js (+26 -0)
📝 frontend/src/locales/da/common.js (+26 -0)
📝 frontend/src/locales/de/common.js (+27 -0)
📝 frontend/src/locales/en/common.js (+26 -0)
📝 frontend/src/locales/es/common.js (+26 -0)

...and 32 more files

📄 Description

Pull Request Type

  • feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #5575
translations #5669

Docs coming after final review.

Description

Adds an opt-in agent skill that lets the LLM pause mid-turn and ask the user clarifying questions through an interactive card in chat, then resume with the answers in context. Off by default, admin-gated, websocket-only (not exposed for API/programmatic agent runs).

Why: Today, when an agent receives an ambiguous prompt it has to guess. This feature gives the agent a structured way to ask for the missing detail instead — without the user needing to restart the turn.

What it does:

  • New ask-user agent tool that accepts a batch of typed questions (free-form input or single/multi-select choice). The agent decides when to call it; the tool descriptions and examples instruct it to batch independent questions and only ask when truly blocked.
  • Interactive card in chat: paginated when there is more than one question, simple form when there is one. Supports text/url/number/date/email/textarea inputs, single/multi-select choice with optional Other field, per-question skip, whole-survey skip, and a countdown timeout bar.
  • Admin settings (Agent Skill Settings modal): enable/disable toggle, max questions per turn (1-10, default 3), response timeout in seconds (10-600, default 120). All capped server-side.
  • Survey persistence: completed surveys are stored on the workspace_chats response JSON blob (no schema change). On reload, the survey re-renders as a read-only card above the agent reply. The Q/A transcript is also injected into the prompt history that gets fed to subsequent LLM turns, so both agent and normal chat can answer follow-ups like "what did I tell you earlier?"

How the wiring works:

  • Tool registration is conditional on the admin setting (server/utils/agents/defaults.js).
  • The handler validates and normalizes per-question, enforces the per-turn cap by truncating rather than rejecting, and returns a numbered Q/A transcript back to the LLM as the tool result.
  • requestUserClarification (server/utils/agents/aibitat/plugins/websocket.js) sends a clarificationRequest over the socket, awaits clarificationResponse, and times out cleanly.
  • Persistence mirrors the existing _pendingCitations / _pendingOutputs pattern: the tool buffers each completed survey on the aibitat instance, and the chat-history plugin drains the buffer into the response JSON when the agent reply is saved.
  • LLM context injection happens in convertToPromptHistory (single inject point covering both agent and normal chat pathways) by appending a tagged transcript to the assistant content.

Files of note:

  • server/utils/agents/aibitat/plugins/ask-questions.js — the tool itself
  • server/utils/agents/aibitat/plugins/websocket.js — requestUserClarification helper
  • server/utils/agents/aibitat/plugins/chat-history.js — persistence buffer drain
  • server/utils/helpers/chat/responses.js — exposes survey to frontend, injects transcript into LLM prompt history
  • frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/ — live interactive card
  • frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/HistoricalClarifyingQuestions/ — read-only persisted card
  • frontend/src/pages/Admin/Agents/AgentSkillSettings/index.jsx — admin settings UI

Visuals (if applicable)

Additional Information

  • All new user-facing strings use t() with defaultValue. Locale JSON files were intentionally not edited — the project convention is that localization is handled by a script as a final pass.
  • No DB migration required. The new clarifyingQuestions field rides inside the existing response JSON column on workspace_chats, alongside sources/metrics/outputs.
  • Skipped and timed-out surveys also persist (with appropriate copy in both the rendered card and the LLM transcript), so the agent never silently loses state.

Developer Validations

  • I ran yarn lint from the root of the repo and committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5577 **Author:** [@angelplusultra](https://github.com/angelplusultra) **Created:** 5/4/2026 **Status:** ✅ Merged **Merged:** 5/21/2026 **Merged by:** [@timothycarambat](https://github.com/timothycarambat) **Base:** `master` ← **Head:** `feat-agent-clarifying-questions` --- ### 📝 Commits (10+) - [`8955b69`](https://github.com/Mintplex-Labs/anything-llm/commit/8955b69c735666fe77bab2f6465f5672473ebc98) initialize feature - [`93128e1`](https://github.com/Mintplex-Labs/anything-llm/commit/93128e1bbfa05edd48fe5826929220b1a0fc4783) lint - [`de075c2`](https://github.com/Mintplex-Labs/anything-llm/commit/de075c29613a57337c3c51b1de404169b9430eff) fix stale comment - [`c05ec96`](https://github.com/Mintplex-Labs/anything-llm/commit/c05ec96c1370155140aaedd2775ef1b7763c2e2c) fix number input - [`ba3615f`](https://github.com/Mintplex-Labs/anything-llm/commit/ba3615ffdc15e5769e8c56dc6c8c413c6361e927) remove needless condition - [`ebbed65`](https://github.com/Mintplex-Labs/anything-llm/commit/ebbed65884b603bdad775147f27861c30a8e3360) add survey persistence - [`d2408d4`](https://github.com/Mintplex-Labs/anything-llm/commit/d2408d4e26338f737c9b55a5acf54d8a8e09da25) add clarifying uestions buffer to aibitat instance with helper methods - [`af0ce41`](https://github.com/Mintplex-Labs/anything-llm/commit/af0ce4199da5f9926455ec2084758e97035bdefc) move plugin specific config data away from aibitat instance and into plugin itself - [`4b0295d`](https://github.com/Mintplex-Labs/anything-llm/commit/4b0295d2a3d2df37a8126329a12922310caf8565) create useTimeoutProgress hook - [`3ef523d`](https://github.com/Mintplex-Labs/anything-llm/commit/3ef523d82d682c3b366743d010fe4297a68a68e0) ui refactor ### 📊 Changes **52 files changed** (+2429 additions, -205 deletions) <details> <summary>View changed files</summary> ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/ChoiceForm.jsx` (+169 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/Footer.jsx` (+93 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/Header.jsx` (+97 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/InputForm.jsx` (+66 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/SurveyBody.jsx` (+82 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/index.jsx` (+273 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/utils.js` (+61 -0) ➕ `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/HistoricalClarifyingQuestions/index.jsx` (+35 -0) 📝 `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/index.jsx` (+6 -1) 📝 `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ToolApprovalRequest/index.jsx` (+7 -24) 📝 `frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx` (+16 -0) 📝 `frontend/src/components/WorkspaceChat/ChatContainer/index.jsx` (+4 -8) ➕ `frontend/src/hooks/useTimeoutProgress.js` (+47 -0) 📝 `frontend/src/locales/ar/common.js` (+26 -0) 📝 `frontend/src/locales/ca/common.js` (+26 -0) 📝 `frontend/src/locales/cs/common.js` (+26 -0) 📝 `frontend/src/locales/da/common.js` (+26 -0) 📝 `frontend/src/locales/de/common.js` (+27 -0) 📝 `frontend/src/locales/en/common.js` (+26 -0) 📝 `frontend/src/locales/es/common.js` (+26 -0) _...and 32 more files_ </details> ### 📄 Description ### Pull Request Type - [x] ✨ feat (New feature) - [ ] 🐛 fix (Bug fix) - [ ] ♻️ refactor (Code refactoring without changing behavior) - [ ] 💄 style (UI style changes) - [ ] 🔨 chore (Build, CI, maintenance) - [ ] 📝 docs (Documentation updates) ### Relevant Issues resolves #5575 translations #5669 Docs coming after final review. ### Description Adds an opt-in agent skill that lets the LLM pause mid-turn and ask the user clarifying questions through an interactive card in chat, then resume with the answers in context. Off by default, admin-gated, websocket-only (not exposed for API/programmatic agent runs). **Why:** Today, when an agent receives an ambiguous prompt it has to guess. This feature gives the agent a structured way to ask for the missing detail instead — without the user needing to restart the turn. **What it does:** - New ask-user agent tool that accepts a batch of typed questions (free-form input or single/multi-select choice). The agent decides when to call it; the tool descriptions and examples instruct it to batch independent questions and only ask when truly blocked. - Interactive card in chat: paginated when there is more than one question, simple form when there is one. Supports text/url/number/date/email/textarea inputs, single/multi-select choice with optional Other field, per-question skip, whole-survey skip, and a countdown timeout bar. - Admin settings (Agent Skill Settings modal): enable/disable toggle, max questions per turn (1-10, default 3), response timeout in seconds (10-600, default 120). All capped server-side. - Survey persistence: completed surveys are stored on the workspace_chats response JSON blob (no schema change). On reload, the survey re-renders as a read-only card above the agent reply. The Q/A transcript is also injected into the prompt history that gets fed to subsequent LLM turns, so both agent and normal chat can answer follow-ups like \"what did I tell you earlier?\" **How the wiring works:** - Tool registration is conditional on the admin setting (server/utils/agents/defaults.js). - The handler validates and normalizes per-question, enforces the per-turn cap by truncating rather than rejecting, and returns a numbered Q/A transcript back to the LLM as the tool result. - requestUserClarification (server/utils/agents/aibitat/plugins/websocket.js) sends a clarificationRequest over the socket, awaits clarificationResponse, and times out cleanly. - Persistence mirrors the existing _pendingCitations / _pendingOutputs pattern: the tool buffers each completed survey on the aibitat instance, and the chat-history plugin drains the buffer into the response JSON when the agent reply is saved. - LLM context injection happens in convertToPromptHistory (single inject point covering both agent and normal chat pathways) by appending a tagged transcript to the assistant content. **Files of note:** - server/utils/agents/aibitat/plugins/ask-questions.js — the tool itself - server/utils/agents/aibitat/plugins/websocket.js — requestUserClarification helper - server/utils/agents/aibitat/plugins/chat-history.js — persistence buffer drain - server/utils/helpers/chat/responses.js — exposes survey to frontend, injects transcript into LLM prompt history - frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ClarifyingQuestion/ — live interactive card - frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/HistoricalClarifyingQuestions/ — read-only persisted card - frontend/src/pages/Admin/Agents/AgentSkillSettings/index.jsx — admin settings UI ### Visuals (if applicable) ### Additional Information - All new user-facing strings use t() with defaultValue. Locale JSON files were intentionally not edited — the project convention is that localization is handled by a script as a final pass. - No DB migration required. The new clarifyingQuestions field rides inside the existing response JSON column on workspace_chats, alongside sources/metrics/outputs. - Skipped and timed-out surveys also persist (with appropriate copy in both the rendered card and the LLM transcript), so the agent never silently loses state. ### Developer Validations - [x] I ran yarn lint from the root of the repo and committed changes - [ ] Relevant documentation has been updated (if applicable) - [x] I have tested my code functionality - [ ] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:21:31 -04:00
yindo closed this issue 2026-06-05 15:21:31 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5488