Skip to content

ToolRegistry

Registry for organizing and managing tools.

Quick Example

from mamba_agents.tools import ToolRegistry
from mamba_agents.tools import read_file, write_file

registry = ToolRegistry()

# Register tools
registry.register(read_file)
registry.register(write_file)

# Get all tools
all_tools = registry.get_all()

# Use with agent
from mamba_agents import Agent
agent = Agent("gpt-4o", tools=all_tools)

API Reference

ToolRegistry

ToolRegistry()

Registry for managing tool functions.

Provides tool registration, enable/disable, and grouping functionality.

Initialize an empty tool registry.

Source code in src/mamba_agents/tools/registry.py
def __init__(self) -> None:
    """Initialize an empty tool registry."""
    self._tools: dict[str, ToolInfo] = {}

register

register(
    func: Callable[..., Any] | None = None,
    *,
    name: str | None = None,
    description: str | None = None,
    group: str | None = None,
) -> Callable[..., Any]

Register a tool function.

Can be used as a decorator with or without arguments.

PARAMETER DESCRIPTION
func

The tool function to register.

TYPE: Callable[..., Any] | None DEFAULT: None

name

Optional custom name (defaults to function name).

TYPE: str | None DEFAULT: None

description

Optional description (defaults to docstring).

TYPE: str | None DEFAULT: None

group

Optional group/namespace.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
Callable[..., Any]

The original function (for decorator use).

Source code in src/mamba_agents/tools/registry.py
def register(
    self,
    func: Callable[..., Any] | None = None,
    *,
    name: str | None = None,
    description: str | None = None,
    group: str | None = None,
) -> Callable[..., Any]:
    """Register a tool function.

    Can be used as a decorator with or without arguments.

    Args:
        func: The tool function to register.
        name: Optional custom name (defaults to function name).
        description: Optional description (defaults to docstring).
        group: Optional group/namespace.

    Returns:
        The original function (for decorator use).
    """

    def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
        tool_name = name or f.__name__
        tool_desc = description or f.__doc__ or ""

        self._tools[tool_name] = ToolInfo(
            name=tool_name,
            func=f,
            description=tool_desc,
            group=group,
        )
        return f

    if func is not None:
        return decorator(func)
    return decorator

get

get(name: str) -> ToolInfo | None

Get a tool by name.

PARAMETER DESCRIPTION
name

The tool name.

TYPE: str

RETURNS DESCRIPTION
ToolInfo | None

ToolInfo if found, None otherwise.

Source code in src/mamba_agents/tools/registry.py
def get(self, name: str) -> ToolInfo | None:
    """Get a tool by name.

    Args:
        name: The tool name.

    Returns:
        ToolInfo if found, None otherwise.
    """
    return self._tools.get(name)

get_enabled

get_enabled() -> list[ToolInfo]

Get all enabled tools.

RETURNS DESCRIPTION
list[ToolInfo]

List of enabled ToolInfo objects.

Source code in src/mamba_agents/tools/registry.py
def get_enabled(self) -> list[ToolInfo]:
    """Get all enabled tools.

    Returns:
        List of enabled ToolInfo objects.
    """
    return [t for t in self._tools.values() if t.enabled]

get_by_group

get_by_group(group: str) -> list[ToolInfo]

Get tools by group.

PARAMETER DESCRIPTION
group

The group name.

TYPE: str

RETURNS DESCRIPTION
list[ToolInfo]

List of ToolInfo objects in the group.

Source code in src/mamba_agents/tools/registry.py
def get_by_group(self, group: str) -> list[ToolInfo]:
    """Get tools by group.

    Args:
        group: The group name.

    Returns:
        List of ToolInfo objects in the group.
    """
    return [t for t in self._tools.values() if t.group == group]

enable

enable(name: str) -> bool

Enable a tool.

PARAMETER DESCRIPTION
name

The tool name.

TYPE: str

RETURNS DESCRIPTION
bool

True if the tool was found and enabled.

Source code in src/mamba_agents/tools/registry.py
def enable(self, name: str) -> bool:
    """Enable a tool.

    Args:
        name: The tool name.

    Returns:
        True if the tool was found and enabled.
    """
    if name in self._tools:
        self._tools[name].enabled = True
        return True
    return False

disable

disable(name: str) -> bool

Disable a tool.

PARAMETER DESCRIPTION
name

The tool name.

TYPE: str

RETURNS DESCRIPTION
bool

True if the tool was found and disabled.

Source code in src/mamba_agents/tools/registry.py
def disable(self, name: str) -> bool:
    """Disable a tool.

    Args:
        name: The tool name.

    Returns:
        True if the tool was found and disabled.
    """
    if name in self._tools:
        self._tools[name].enabled = False
        return True
    return False

list_all

list_all() -> list[str]

List all registered tool names.

RETURNS DESCRIPTION
list[str]

List of tool names.

Source code in src/mamba_agents/tools/registry.py
def list_all(self) -> list[str]:
    """List all registered tool names.

    Returns:
        List of tool names.
    """
    return list(self._tools.keys())

as_functions

as_functions() -> list[Callable[..., Any]]

Get all enabled tools as a list of functions.

RETURNS DESCRIPTION
list[Callable[..., Any]]

List of tool functions.

Source code in src/mamba_agents/tools/registry.py
def as_functions(self) -> list[Callable[..., Any]]:
    """Get all enabled tools as a list of functions.

    Returns:
        List of tool functions.
    """
    return [t.func for t in self.get_enabled()]