Tool System
Loom’s tool system provides AI agents with capabilities to interact with the development environment through structured JSON schemas. Tools are implemented inloom-cli-tools and registered at runtime.
Architecture
ToolRegistry: Central registry for all available toolsToolContext: Execution context (workspace root, environment)ToolDefinition: JSON schema for LLM consumptionToolExecutionOutcome: Result type (success or error)
Tool Registration
Tools are registered during CLI initialization:Built-in Tools
read_file
Read file contents from the workspace.Path to file (absolute or relative to workspace)
Maximum bytes to read (default: 1MB)
- Path validation (prevents directory traversal)
- Workspace boundary enforcement
- Automatic truncation for large files
- UTF-8 lossy conversion
edit_file
Apply snippet-based edits to files.Path to file (created if doesn’t exist)
List of edit operationsEach edit:
old_str: Text to find (empty string for new files)new_str: Replacement textreplace_all: Replace all occurrences (default: false)
- Edits applied sequentially
- If
old_stris empty: appendnew_strto file (create if needed) - If
old_strfound once: replace withnew_str - If
old_strfound multiple times: error (unlessreplace_all: true) - If
old_strnot found: error
bash
Execute shell commands in the workspace.Shell command to execute
Working directory (relative to workspace, default: workspace root)
Timeout in seconds (default: 60, max: 300)
- Runs commands via
sh -c - Respects workspace boundaries (cwd validation)
- Automatic timeout (prevents hanging)
- Output truncation (256KB per stream)
- Captures both stdout and stderr
list_files
List files in a directory (glob-like functionality).Directory path (default: workspace root)
List files recursively (default: false)
Maximum recursion depth (default: 10)
web_search
Perform web searches via Loom server proxy.Search query in natural language
Maximum results (default: 5, max: 10)
POST /proxy/cse
Providers:
WebSearchToolGoogle: Google Custom Search EngineWebSearchToolSerper: Serper.dev API
Web search requires API keys configured on the server. The tool automatically retries on transient failures using exponential backoff.
oracle
Reserved for future use (AI model introspection).Tool Context
Every tool receives aToolContext with:
Error Handling
Tools returnResult<serde_json::Value, ToolError>:
1
Tool returns error
2
Executor wraps error
3
Error sent to LLM
4
LLM retries or adapts
The agent can correct the path or try a different approach.
Security
Path Validation
All file tools validate paths:- Directory traversal (
../../../etc/passwd) - Absolute paths outside workspace (
/etc/shadow) - Symlink escape (via
canonicalize())
Bash Sandboxing
- Commands run in workspace subdirectory
- No network access (unless container allows)
- Timeout prevents infinite loops
- Output truncation prevents memory exhaustion
Resource Limits
Testing
Loom tools use property-based testing withproptest:
- Path validation (traversal, absolute, symlinks)
- Content preservation (UTF-8, truncation)
- Error conditions (not found, permissions)
- Edge cases (empty files, large files)
Adding Custom Tools
1
Implement the Tool trait
2
Register in the registry
3
Write tests
Best Practices
Validate all inputs
Use schema validation and runtime checks. Never trust LLM-generated arguments.
Enforce resource limits
Set timeouts, max sizes, and depth limits to prevent abuse.
Return structured errors
Provide clear error messages the LLM can understand and act on.
Test with proptest
Use property-based testing to find edge cases.
Log tool execution
Use tracing for debugging:
tracing::debug!("executing tool")Keep tools atomic
One tool = one operation. Compose complex workflows in the agent layer.