ToolRegistry

from mango.tools.base import ToolRegistry

Manages tool registration and execution. The LLM receives tool definitions from the registry and calls tools by name.

Usage

from mango.tools.base import ToolRegistry
from mango.tools import build_mongo_tools

tools = ToolRegistry()

# Register built-in MongoDB tools
for tool in build_mongo_tools(db, memory):
    tools.register(tool)

# Register a custom tool
tools.register(MyCustomTool())

Methods

register(tool: Tool) → None

Register a tool. Raises if a tool with the same name is already registered.

tools.register(MyTool())

get_definitions() → list[ToolDef]

Returns all tool definitions. Passed to the LLM on every chat() call.

definitions = tools.get_definitions()

execute(tool_name, **kwargs) → ToolResult

async

Execute a tool by name with the given arguments.

result = await tools.execute("run_mql", operation="count", collection="users")
print(result.success, result.data)

Raises KeyError if tool_name is not registered.

build_mongo_tools

from mango.tools import build_mongo_tools

tools_list = build_mongo_tools(
    db: NoSQLRunner,
    memory: MemoryService | None = None,
)

Returns all built-in MongoDB tools as a list ready to register. Pass memory to enable memory-related tools (search_saved_correct_tool_uses, save_text_memory).