Class: Rubino::Tools::QuestionTool

Inherits:
Base
  • Object
show all
Defined in:
lib/rubino/tools/question_tool.rb

Overview

Tool that asks the user interactive questions with predefined options. Allows the agent to gather clarification or preferences from the user.

Constant Summary collapse

NO_ANSWER =

Deterministic result when no user answer is available — the UI’s #ask returned nil (non-interactive / piped session, or the user gave no response). Fail closed instead of reading ambient stdin or silently picking an option (#107): never assume a choice on the user’s behalf.

"No answer: no interactive user input available " \
"(non-interactive session, or the user gave no response). " \
"Do not assume a choice on the user's behalf; proceed with the " \
"safest option and state the assumption, or finish and report " \
"the open question."

Instance Attribute Summary

Attributes inherited from Base

#cancel_token, #read_tracker, #stream_chunk

Instance Method Summary collapse

Methods inherited from Base

#cancellation_requested?, #config_key, #emit_chunk, #risky?, #to_tool_definition, workspace_root, workspace_roots

Instance Method Details

#call(arguments) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rubino/tools/question_tool.rb', line 61

def call(arguments)
  question = arguments["question"] || arguments[:question]
  options = arguments["options"] || arguments[:options]
  multiple = arguments["multiple"] || arguments[:multiple] || false

  ui = Rubino.ui

  if options && !options.empty?
    ask_with_options(ui, question, options, multiple)
  else
    ask_freeform(ui, question)
  end
end

#descriptionObject



12
13
14
15
16
# File 'lib/rubino/tools/question_tool.rb', line 12

def description
  "Ask the user a question with optional predefined choices. " \
    "Use this when you need clarification, user preferences, or a decision. " \
    "The user can select from options or type a custom answer."
end

#input_schemaObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubino/tools/question_tool.rb', line 18

def input_schema
  {
    type: "object",
    properties: {
      question: {
        type: "string",
        description: "The question to ask the user"
      },
      options: {
        type: "array",
        items: {
          type: "object",
          properties: {
            label: { type: "string", description: "Short display text for the option" },
            description: { type: "string", description: "Explanation of this choice" }
          },
          required: %w[label]
        },
        description: "Available choices (optional). A 'Type your own' option is added automatically."
      },
      multiple: {
        type: "boolean",
        description: "Allow selecting multiple choices (default: false)"
      }
    },
    required: %w[question]
  }
end

#nameObject



8
9
10
# File 'lib/rubino/tools/question_tool.rb', line 8

def name
  "question"
end

#risk_levelObject



47
48
49
# File 'lib/rubino/tools/question_tool.rb', line 47

def risk_level
  :low
end