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):
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)
Never raises: an unregistered name returns ToolResult(success=False, error="Unknown tool '…'. Available: [...]"), and an exception raised inside Tool.execute() is caught and returned as ToolResult(success=False, error=str(exc), error_kind=type(exc).__name__) — error_kind is what the agent uses to decide whether to retry.
__contains__ / __len__
"run_mql" in tools # True if a tool with that name is registered
len(tools) # number of registered tools
build_mongo_tools
from mango.tools import build_mongo_tools
tools_list = build_mongo_tools(
backend: MongoRunner,
max_rows: int = 100, # row cap for run_mql
validate: bool = True, # pre-execution MQL validation
)
Returns the six built-in MongoDB tools (list_collections, search_collections, describe_collection, inspect_field, collection_stats, run_mql) ready to register. There is no memory parameter: memory examples are pre-injected into the prompt by the agent, and save_text_memory must be registered separately with SaveTextMemoryTool(memory).