Tool System
Tool Architecture
Tools are stateless callable units that agents use to perform actions (read files, run code, search memory, call external APIs, etc.). Each tool has:
- A name (unique in the registry)
- A description (for the agent prompt)
- An input_schema (JSON Schema–style:
type,properties,required) - A **run(kwargs) method that returns a string (so the agent can parse or display the result)
The agent receives a list of tools and invokes them by outputting a fixed format (e.g. TOOL: <name> and INPUT: <json>). The tool runner validates arguments, calls the tool, and returns the result string (or an error message).
Tool Registry
- Registration: Tools register themselves when their module is imported (e.g. in each category’s
__init__.pyviaregister(SomeTool())). - Lookup:
get(name)returns theToolfor that name;list_tools()returns all registered tools. - Usage: The agent (or any code) uses
run_tool(name, args)to execute a tool by name with a dict of arguments.
Tool Runner
- Role: Execute a tool by name with validated arguments and safe error handling.
- Steps:
- Resolve tool by name from the registry.
- Validate
argsagainst the tool’sinput_schema(required keys, types). - Call
tool.run(**args). - Return the result string, or a formatted error string on validation failure or exception.
Creating a New Tool
- Subclass
Toolfromhivemind.tools.base. - Set
name,description, andinput_schema(e.g.properties,required). - Implement
run(self, **kwargs) -> str. - Register the tool so it’s loaded (e.g. in the package’s
__init__.pyor a category__init__.py):register(MyTool()).
Example implementation:
from pathlib import Path
from hivemind.tools.base import Tool
from hivemind.tools.registry import register
class WriteFileTool(Tool):
name = "write_file"
description = "Write content to a file. Creates parent dirs if needed. Overwrites existing file."
input_schema = {
"type": "object",
"properties": {
"path": {"type": "string", "description": "Path to the file"},
"content": {"type": "string", "description": "Content to write"},
},
"required": ["path", "content"],
}
def run(self, **kwargs) -> str:
path = kwargs.get("path")
content = kwargs.get("content")
if not path or not isinstance(path, str):
return "Error: path must be a non-empty string"
if content is None:
return "Error: content is required"
p = Path(path).resolve()
try:
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(content, encoding="utf-8")
return f"Wrote {len(content)} characters to {p}"
except Exception as e:
return f"Error writing file: {e}"
register(WriteFileTool())
Ensure the module is imported (e.g. in hivemind.tools or the right category __init__.py) so the tool is registered when the app loads.
Tool Categories
Tools are grouped by domain; each category lives in its own subpackage and registers in its __init__.py. Categories include:
| Category | Examples |
|---|---|
| Research | literature review, citation graph, topic extraction, arxiv search, web search |
| Coding | codebase indexer, dependency graph, architecture analyzer, refactor candidates, run Python, lint, generate tests |
| Data science | dataset profile, outlier detection, correlation, distribution report, feature importance |
| Documents | docproc extraction, knowledge graph, timeline extraction, summarize, convert to Markdown |
| Experiments | grid search, swarm experiment runner, Monte Carlo, statistical tests, result comparator |
| Memory | store, list, search, summarize, tag, delete memory |
| Filesystem | read_file, write_file, list_directory, search_files, file metadata |
| System | run_shell_command, environment variables, disk/cpu/memory usage |
| Knowledge | document topic extractor, citation graph builder, knowledge graph extractor, timeline extractor |
| Flagship | docproc corpus pipeline, research graph builder, repository semantic map, distributed document analysis |
Use list_tools() or inspect the hivemind.tools package to see the full set (120+ tools).
Smart tool selection (v1)
When config has [tools] top_k > 0, the agent does not receive all tools. Instead:
- Tool selector (
hivemind.tools.selector): embeds the task description and each tool’s name + description (using the same embedding function as memory), computes cosine similarity, and returns the top_k most relevant tools. - Category filter: If
[tools] enabledis set (e.g.["research", "coding", "documents"]), only tools in those categories are considered; then top_k is applied within that set. - Tool category: Each tool can set an optional
categoryattribute (e.g."research","coding"). If unset, the selector infers it from the tool’s module path (e.g.hivemind.tools.research.*→research).
This keeps the agent prompt smaller and focuses it on the most relevant tools for the task.
Plugin system (v1)
External packages can register tools without modifying the Hivemind codebase.
- Entry point: Declare a group
hivemind.pluginsin your package’spyproject.toml:[project.entry-points."hivemind.plugins"]
bio = "hivemind_plugin_bio:register" - Loader: When
hivemind.toolsis imported, the plugin loader (hivemind.plugins.plugin_loader) discovers all entry points, loads each callable, and expects either a list ofToolinstances or a function that registers tools withhivemind.tools.registry.register. - Registry: Loaded plugins are recorded in
hivemind.plugins.plugin_registry(name, version, list of tool names registered).
Example plugin implementation: the callable can return [Tool1(), Tool2()] or call register(tool) for each tool and return nothing. See Development for project structure and adding plugins.