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 not community.

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 to bahulam.community.<handle>.<verb>.

Tool Attributes

AttributeTypePurpose
namestrRegistry key, agent-facing identifier.
descriptionstrShown to the LLM.
parametersdictJSON schema, Claude API format.
workspace_idstrFor sandbox executor + billing attribution.
custom_tool_pathstrRelative path from workspace root — the MicroVM uses this to locate the source.
proprietaryboolDefault False for community tools. Bahulam-verified tools set True.
llm_visibleboolDefault True. Set False for hidden intercept-only tools.
returns_curated_summaryboolDefault 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:

  1. Resolves configs/workspaces/community/<handle>/<name>/workspace.yaml.
  2. Runs imports: (platform tools you bound).
  3. Walks custom_tools.path (tools/ by default), imports every *.py.
  4. Each module executes → your SomeTool.register() calls fire.
  5. Admission validator runs. Unknown names in tools: → fatal.
  6. Factory constructs the agent, binds the whitelisted tools.
  7. 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.).