SkyRL
API ReferenceSkyRL-Gym

Tools

Tools API — ToolGroup, tool decorator.

ToolGroup

class ToolGroup

ToolGroup(name: str)

A group of tools that can be used together.

Functions:

Attributes:

NameTypeDescription
name
Source code in skyrl-gym/skyrl_gym/tools/core.py:19-60
class ToolGroup:
    """
    A group of tools that can be used together.
    """

    def __init__(self, name: str):
        self.name = name
        self._tool_registry: Dict[str, Callable] = {}
        self._register_tools()

    def get_name(self):
        return self.name

    def _register_tools(self):
        # Register all methods decorated with @tool

        # Tool names must be unique across tool groups.
        # TODO: Support duplicate tool names across tool groups via namespacing
        for attr_name in dir(self):
            # Look for the descriptor on the class, not the instance
            raw = getattr(type(self), attr_name, None)
            if isinstance(raw, tool):
                self._tool_registry[raw.name] = getattr(self, attr_name)

    def get_tool(self, name: str) -> Optional[Callable]:
        # Get a tool by name, returns None if not found
        return self._tool_registry.get(name)

    def get_tool_names(self) -> List[str]:
        # Get all available tool names
        return list(self._tool_registry.keys())

    def execute_tool(self, name: str, *args, **kwargs) -> Any:
        # Execute a tool by name with given arguments
        tool_func = self.get_tool(name)
        if tool_func:
            return tool_func(*args, **kwargs)
        raise ValueError(f"Tool '{name}' not found in group '{self.name}'.")

    def get_tool_to_group_mapping(self) -> Dict[str, str]:
        # Get mapping of tool names to group name
        return {name: self.name for name in self._tool_registry}

attr name

name = name

method get_name

get_name()
Source code in skyrl-gym/skyrl_gym/tools/core.py:29-30
    def get_name(self):
        return self.name

method get_tool

get_tool(name: str) -> Optional[Callable]
Source code in skyrl-gym/skyrl_gym/tools/core.py:43-45
    def get_tool(self, name: str) -> Optional[Callable]:
        # Get a tool by name, returns None if not found
        return self._tool_registry.get(name)

method get_tool_names

get_tool_names() -> List[str]
Source code in skyrl-gym/skyrl_gym/tools/core.py:47-49
    def get_tool_names(self) -> List[str]:
        # Get all available tool names
        return list(self._tool_registry.keys())

method execute_tool

execute_tool(name: str, *args: str, **kwargs: str) -> Any
Source code in skyrl-gym/skyrl_gym/tools/core.py:51-56
    def execute_tool(self, name: str, *args, **kwargs) -> Any:
        # Execute a tool by name with given arguments
        tool_func = self.get_tool(name)
        if tool_func:
            return tool_func(*args, **kwargs)
        raise ValueError(f"Tool '{name}' not found in group '{self.name}'.")

method get_tool_to_group_mapping

get_tool_to_group_mapping() -> Dict[str, str]
Source code in skyrl-gym/skyrl_gym/tools/core.py:58-60
    def get_tool_to_group_mapping(self) -> Dict[str, str]:
        # Get mapping of tool names to group name
        return {name: self.name for name in self._tool_registry}

Tool Decorator

class tool

tool(func: Callable)

A tool that can be used to execute a function.

Attributes:

NameTypeDescription
func
name
Source code in skyrl-gym/skyrl_gym/tools/core.py:4-16
class tool:
    """
    A tool that can be used to execute a function.
    """

    def __init__(self, func: Callable):
        self.func = func
        self.name = func.__name__

    def __get__(self, instance, owner):
        if instance is None:
            return self  # Return the descriptor itself when accessed from the class
        return lambda *args, **kwargs: self.func(instance, *args, **kwargs)

attr func

func = func

attr name

name = func.__name__

On this page