Skip to main content

tinyharness_lib/tools/
question.rs

1use std::collections::HashMap;
2
3use crate::tools::tool::{BoxFuture, Tool, ToolCategory, make_tool};
4
5/// Stub function — the question tool is handled specially in the agent loop
6/// (similar to switch_mode), so this function is never actually called.
7/// It exists only to satisfy the Tool struct's function field requirement.
8fn question_tool_stub(_args: HashMap<String, String>) -> BoxFuture<'static, String> {
9    Box::pin(async move {
10        "Error: question tool should be handled by the agent loop, not executed directly."
11            .to_string()
12    })
13}
14
15/// Build a custom JSON Schema for the question tool.
16/// This is needed because the "answers" parameter is an array of strings,
17/// not a simple string — so `build_string_params_schema` cannot be used.
18fn build_question_schema() -> schemars::Schema {
19    let schema_value = serde_json::json!({
20        "type": "object",
21        "properties": {
22            "question": {
23                "type": "string",
24                "description": "The question to ask the user about an implementation detail or decision"
25            },
26            "answers": {
27                "type": "array",
28                "items": {
29                    "type": "string"
30                },
31                "description": "A list of possible answers the user can choose from. Must contain at least one option."
32            }
33        },
34        "required": ["question", "answers"],
35        "additionalProperties": false
36    });
37
38    serde_json::from_value(schema_value)
39        .unwrap_or_else(|_| serde_json::from_value(serde_json::json!(true)).unwrap())
40}
41
42pub fn question_tool_entry() -> Tool {
43    make_tool(
44        "question",
45        "Ask the user a question with a list of possible answers. Use this when you need clarification about implementation details, design decisions, or any choice that affects how you should proceed. The tool will present the question and options to the user, and return their selected answer.",
46        ToolCategory::Signal,
47        build_question_schema(),
48        question_tool_stub,
49    )
50}