Skip to main content

tinyharness_lib/tools/
switch_mode.rs

1use std::collections::HashMap;
2
3use crate::extract_args;
4use crate::mode::AgentMode;
5use crate::tools::tool::{BoxFuture, ToolCategory, build_string_params_schema, make_tool};
6
7pub fn switch_mode_tool_entry() -> crate::tools::tool::Tool {
8    make_tool(
9        "switch_mode",
10        "Switch the assistant to a different operating mode. Use 'planning' to analyze, research, and plan without making changes. Use 'agent' to write code and execute commands (escalate from planning). Use 'casual' for general conversation.",
11        ToolCategory::Signal,
12        build_string_params_schema(
13            &[(
14                "mode",
15                "The mode to switch to: 'casual', 'planning', or 'agent'",
16            )],
17            &[],
18        ),
19        |args| Box::pin(switch_mode_tool(args)),
20    )
21}
22
23pub fn switch_mode_tool(args: HashMap<String, String>) -> BoxFuture<'static, String> {
24    Box::pin(async move {
25        extract_args!(args, mode);
26
27        let mode_str = mode.trim().to_string();
28
29        // Validate the mode string
30        match mode_str.parse::<AgentMode>() {
31            Ok(parsed_mode) => format!(
32                "SUCCESS: Mode switched to '{}'. The assistant is now in {} mode and will use the appropriate toolset and behavior.",
33                parsed_mode, parsed_mode
34            ),
35            Err(e) => {
36                format!("Error: {}. Valid modes: casual, planning, agent", e)
37            }
38        }
39    })
40}