Skip to main content
Glama

switch_modes

Activate specific operational modes such as editing, interactive, planning, or one-shot to adapt the coding agent's behavior for different tasks.

Instructions

Activates the desired modes, like ["editing", "interactive"] or ["planning", "one-shot"].

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modesYesThe names of the modes to activate.

Implementation Reference

  • The SwitchModesTool class implements the execution logic (handler) for the 'switch_modes' tool. It accepts a list of mode names, loads the corresponding SerenaAgentMode instances, sets them on the agent, and returns a detailed confirmation including prompts and active tools.
    class SwitchModesTool(Tool, ToolMarkerOptional):
        """
        Activates modes by providing a list of their names
        """
    
        def apply(self, modes: list[str]) -> str:
            """
            Activates the desired modes, like ["editing", "interactive"] or ["planning", "one-shot"]
    
            :param modes: the names of the modes to activate
            """
            mode_instances = [SerenaAgentMode.load(mode) for mode in modes]
            self.agent.set_modes(mode_instances)
    
            # Inform the Agent about the activated modes and the currently active tools
            result_str = f"Successfully activated modes: {', '.join([mode.name for mode in mode_instances])}" + "\n"
            result_str += "\n".join([mode_instance.prompt for mode_instance in mode_instances]) + "\n"
            result_str += f"Currently active tools: {', '.join(self.agent.get_active_tool_names())}"
            return result_str
  • The ToolRegistry singleton automatically discovers and registers all subclasses of Tool in the 'serena.tools' package, including SwitchModesTool, deriving its name 'switch_modes' and marking it as optional.
    def __init__(self) -> None:
        self._tool_dict: dict[str, RegisteredTool] = {}
        for cls in iter_subclasses(Tool):
            if not any(cls.__module__.startswith(pkg) for pkg in tool_packages):
                continue
            is_optional = issubclass(cls, ToolMarkerOptional)
            name = cls.get_name_from_cls()
            if name in self._tool_dict:
                raise ValueError(f"Duplicate tool name found: {name}. Tool classes must have unique names.")
            self._tool_dict[name] = RegisteredTool(tool_class=cls, is_optional=is_optional, tool_name=name)
  • The get_name_from_cls class method in the base Tool class converts 'SwitchModesTool' to the tool name 'switch_modes' used for registration and MCP exposure.
    def get_name_from_cls(cls) -> str:
        name = cls.__name__
        if name.endswith("Tool"):
            name = name[:-4]
        # convert to snake_case
        name = "".join(["_" + c.lower() if c.isupper() else c for c in name]).lstrip("_")
        return name
    
    def get_name(self) -> str:
        return self.get_name_from_cls()
  • In SerenaAgent.__init__, all registered tools including SwitchModesTool are instantiated from the ToolRegistry and stored in self._all_tools for later exposure.
    # instantiate all tool classes
    self._all_tools: dict[type[Tool], Tool] = {tool_class: tool_class(self) for tool_class in ToolRegistry().get_all_tool_classes()}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/oraios/serena'

If you have feedback or need assistance with the MCP directory API, please join our Discord server