Custom Tools
Your workspace’s tools live under tools/ as Python files. Each file
declares one or more SandboxTool subclasses. When your workspace loads,
Bahulam imports the file — registration happens as a side effect.
The Pattern
Every custom tool is a SandboxTool subclass with:
from app.agent.tools.base import SandboxTool
class MyTool(SandboxTool):
# Registry key. Agent asks by this name.
name = "bahulam.community.<your-handle>.<verb>"
# Shown to the LLM in tool lists.
description = "One sentence, active voice."
# Sandbox metadata used by the executor.
workspace_id = "community/<your-handle>/<workspace-name>"
custom_tool_path = "tools/my_tool.py"
# JSON schema for arguments (Claude API format).
parameters = {
"type": "object",
"properties": {
"person": {"type": "string", "description": "Who to greet."},
},
"required": ["person"],
}
# Body that would run inside the MicroVM. In dev
# (SANDBOX_EXECUTOR=mock) it is NOT called — see Sandbox Runtime.
def _inside_sandbox(self, person: str) -> dict:
return {"greeting": f"Hello, {person}!"}
# Register at module bottom — module import fires this.
MyTool.register()That’s the whole surface.
Namespace Rules
Required prefix: bahulam.community.<your-handle>.<verb>
The <your-handle> MUST match the community/<handle>/ segment of your
workspace directory. This is how the admission validator ties tools to
authors for the community-credits pipeline (PRD-086 §7.4).
Rejected at admission:
bahulam.powerbi.*— reserved for the Bahulam-verified Power BI stack.bahulam.tableau.*,bahulam.looker.*,bahulam.iot.*— reserved.- Any
bahulam.<verified-category>.*where<category>is notcommunity.
Allowed but not recommended:
- Bare names like
my_greeter(no prefix). These work but pollute the global namespace and can collide with future platform tools. Stick tobahulam.community.<handle>.<verb>.
Tool Attributes
| Attribute | Type | Purpose |
|---|---|---|
name | str | Registry key, agent-facing identifier. |
description | str | Shown to the LLM. |
parameters | dict | JSON schema, Claude API format. |
workspace_id | str | For sandbox executor + billing attribution. |
custom_tool_path | str | Relative path from workspace root — the MicroVM uses this to locate the source. |
proprietary | bool | Default False for community tools. Bahulam-verified tools set True. |
llm_visible | bool | Default True. Set False for hidden intercept-only tools. |
returns_curated_summary | bool | Default False. Set True for tools that self-summarize (sub-agents). |
The _inside_sandbox Convention
The body that runs inside the MicroVM should live in a method you
control — typically named _inside_sandbox or the tool’s verb. The base
class’s execute() handles routing (ApprovalPolicy check, executor
dispatch); your subclass just provides the domain logic.
Why the separation:
- In dev with
SANDBOX_EXECUTOR=mock,execute()returns a marker instead of invoking your method. Your logic is never called. - In prod with
SANDBOX_EXECUTOR=microvm, the executor packages the tool file + args, ships to the MicroVM, and the MicroVM invokes your method in isolation.
Neither path lets you side-effect the main Bahulam FastAPI process at tool-call time. Any real work happens in the sandbox.
Sub-Sections in One File
Multiple tools per file is fine and encouraged for related tools:
from app.agent.tools.base import SandboxTool, register_all
class ListItemsTool(SandboxTool):
name = "bahulam.community.acme.list_items"
# ...
class AddItemTool(SandboxTool):
name = "bahulam.community.acme.add_item"
# ...
class RemoveItemTool(SandboxTool):
name = "bahulam.community.acme.remove_item"
# ...
# Batch-register at the end.
register_all(ListItemsTool, AddItemTool, RemoveItemTool)register_all() is a convenience shortcut for many Cls.register() calls.
Parameter Schema Tips
The parameters field is passed to the LLM verbatim as a JSON schema. Two
practical patterns:
Required + optional:
parameters = {
"type": "object",
"properties": {
"id": {"type": "string", "description": "Item id."},
"force": {"type": "boolean", "default": False, "description": "Skip confirmation."},
},
"required": ["id"],
}Enum values:
parameters = {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["create", "update", "delete"],
},
},
"required": ["action"],
}Nested objects:
parameters = {
"type": "object",
"properties": {
"config": {
"type": "object",
"properties": {
"region": {"type": "string"},
"retries": {"type": "integer", "minimum": 0, "maximum": 5},
},
},
},
}Keep parameter names snake_case. LLMs are consistent with that convention across the ecosystem.
Discovery + Registration Under the Hood
When Bahulam loads your workspace:
- Resolves
configs/workspaces/community/<handle>/<name>/workspace.yaml. - Runs
imports:(platform tools you bound). - Walks
custom_tools.path(tools/by default), imports every*.py. - Each module executes → your
SomeTool.register()calls fire. - Admission validator runs. Unknown names in
tools:→ fatal. - Factory constructs the agent, binds the whitelisted tools.
- Agent starts.
Files starting with _ (except __init__.py) are skipped, so you can keep
private helpers like _utils.py outside the registration walk.
Testing Your Tool
See Local Testing for the round-trip flow. In short:
from app.agent.workspace_agent import WorkspaceAgent, RunContext
agent = await WorkspaceAgent.from_config(
"community/your-handle/your-workspace",
RunContext(job_id="test", gateway=g, tool_executor=e,
session_id="s", channel="api", user_id="u"),
)Load errors are structured — the admission validator returns
ValidationError codes you can grep against (reserved_namespace_shadowing,
limits_memory_exceeded, tool_not_registered, etc.).