Documentation
¶
Index ¶
- Constants
- func GetDescription(includePreviewMarkdown bool, includePreviewHTML bool) string
- func ValidateHTMLPreview(preview string) string
- type Annotation
- type Config
- type Input
- type Output
- type Question
- type QuestionOption
- type Tool
- func (t *Tool) BackfillInput(ctx context.Context, input map[string]any) map[string]any
- func (t *Tool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)
- func (t *Tool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
- func (t *Tool) Definition() tool.Definition
- func (t *Tool) Description(ctx context.Context) (string, error)
- func (t *Tool) FormatResult(data any) string
- func (t *Tool) IsConcurrencySafe(input map[string]any) bool
- func (t *Tool) IsEnabled() bool
- func (t *Tool) IsReadOnly(input map[string]any) bool
- func (t *Tool) SetPromptFn(promptFn types.PromptFn)
- func (t *Tool) SetReader(reader *bufio.Reader)
- func (t *Tool) SetTimeout(timeout time.Duration)
- func (t *Tool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)
Constants ¶
const Description = `Asks the user multiple choice questions to gather information, clarify ambiguity, understand preferences, make decisions or offer them choices.
Use this tool when progress is blocked by missing user input.
This tool is for real clarification, preference gathering, or decision points during execution. It is not for narration, status updates, or asking for approval that another tool already handles.
## Good reasons to use it
- The request is ambiguous and multiple valid implementations exist
- A product or UX preference must be chosen by the user
- You need a concrete decision before continuing
- You need structured answers for recommendations, research direction, or implementation scope
- You need the user to choose between tradeoffs that you cannot resolve from evidence alone
## Do NOT use it when
- you already have enough information to proceed safely
- you are only giving a status update
- you are asking "should I continue?"
- you are in plan mode and simply need plan approval; use ` + "`exit_plan_mode`" + ` for that
- you could instead verify the answer from the repository or a reliable source
## Question design rules
- Ask the minimum number of questions needed to unblock progress
- Prefer one focused question over a large survey unless batching is clearly useful
- Keep each question concise and concrete
- Make sure each option represents a real decision the user can understand
- Use 2 to 10 options
- Use ` + "`multiSelect: true`" + ` only when multiple answers are genuinely useful
- Put the recommended option first and suffix the label with ` + "\"(Recommended)\"" + `
- Do NOT include an explicit ` + "\"Other\"" + ` option; the UI/runtime adds a free-text path automatically
- If a free-text answer is likely, keep the structured choices broad and complementary rather than overly exhaustive
## Examples
Good:
- "Which deployment target should I optimize for first?"
- "Which of these auth approaches matches your preference?"
- "What kind of project should I research for you?"
- "Which of these rollout strategies do you prefer for this change?"
Bad:
- "Should I proceed?"
- "Is my plan good?"
- "Anything else?"
- "Can you confirm this fact?" when the fact could be verified from tools
## Plan mode note
In plan mode, use this tool only to resolve requirement gaps before finalizing the plan. Do not ask the user to approve the plan through this tool.`
Description is the tool description.
const PreviewFeatureDescriptionHTML = `
Preview feature:
Use the optional ` + "`preview`" + ` field on options when presenting concrete artifacts that users need to visually compare:
- HTML mockups of UI layouts or components
- Formatted code snippets showing different implementations
- Visual comparisons or diagrams
Preview content must be a self-contained HTML fragment (no <html>/<body> wrapper, no <script> or <style> tags — use inline style attributes instead). Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).
`
PreviewFeatureDescriptionHTML is the preview feature guidance for HTML format.
const PreviewFeatureDescriptionMarkdown = `
Preview feature:
Use the optional ` + "`preview`" + ` field on options when presenting concrete artifacts that users need to visually compare:
- ASCII mockups of UI layouts or components
- Code snippets showing different implementations
- Diagram variations
- Configuration examples
Preview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).
`
PreviewFeatureDescriptionMarkdown is the preview feature guidance for markdown format.
const SearchHint = "prompt the user with a multiple choice question"
SearchHint is a hint for tool search functionality.
const ToolName = "ask_user_question"
ToolName is the tool name.
Variables ¶
This section is empty.
Functions ¶
func GetDescription ¶
GetDescription returns the full description, optionally including preview feature guidance.
func ValidateHTMLPreview ¶
ValidateHTMLPreview validates HTML preview content. Returns an error message if invalid, nil if valid.
Types ¶
type Annotation ¶
type Annotation struct {
Preview string `json:"preview,omitempty"`
Notes string `json:"notes,omitempty"`
}
Annotation contains additional info about a user's answer.
type Input ¶
type Input struct {
Questions []Question `json:"questions"`
Answers map[string]string `json:"answers,omitempty"`
Annotations map[string]Annotation `json:"annotations,omitempty"`
}
Input represents the tool input.
func (*Input) FormatForDisplay ¶
FormatForDisplay formats the questions for display to user.
type Output ¶
type Output struct {
Questions []Question `json:"questions"`
Answers map[string]string `json:"answers"`
Annotations map[string]Annotation `json:"annotations,omitempty"`
}
Output represents the tool output.
type Question ¶
type Question struct {
Question string `json:"question"`
Header string `json:"header"`
Options []QuestionOption `json:"options"`
MultiSelect bool `json:"multiSelect,omitempty"`
}
Question represents a question to ask the user.
func (*Question) GetOptionByIndex ¶
func (q *Question) GetOptionByIndex(index int) *QuestionOption
GetOptionByIndex returns the option for a given question and index.
func (*Question) GetOptionByLabel ¶
func (q *Question) GetOptionByLabel(label string) *QuestionOption
GetOptionByLabel returns the option for a given question and label.
type QuestionOption ¶
type QuestionOption struct {
Label string `json:"label"`
Description string `json:"description"`
Preview string `json:"preview,omitempty"`
}
QuestionOption represents an option for a question.
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool represents the AskUserQuestion tool.
func (*Tool) BackfillInput ¶
BackfillInput enriches a shallow clone of the parsed input with derived fields.
func (*Tool) Call ¶
func (t *Tool) Call( ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn, ) (tool.CallResult, error)
Call executes the tool.
func (*Tool) CheckPermissions ¶
func (t *Tool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
CheckPermissions marks AskUserQuestion as locally allowed.
func (*Tool) Definition ¶
func (t *Tool) Definition() tool.Definition
Definition returns the tool definition.
func (*Tool) Description ¶
Description returns human-readable description.
func (*Tool) FormatResult ¶
FormatResult serialises the tool output into the tool_result content string.
func (*Tool) IsConcurrencySafe ¶
IsConcurrencySafe reports that AskUserQuestion can run concurrently.
func (*Tool) IsReadOnly ¶
IsReadOnly reports that AskUserQuestion does not modify state.
func (*Tool) SetPromptFn ¶
SetPromptFn sets a prompt function for structured prompting.
func (*Tool) SetTimeout ¶
SetTimeout sets the input timeout.