sgr-agent-tools
11 reusable file-system tools for sgr-agent based AI agents.
Generic over FileBackend trait — implement it once for your runtime (RPC, local fs, in-memory mock) and get battle-tested tools out of the box.
Tools
| # | Tool | Type | Description |
|---|---|---|---|
| 1 | ReadTool |
observe | Read file with trust metadata header |
| 2 | WriteTool |
act | Write file with JSON auto-repair (llm_json) |
| 3 | DeleteTool |
act | Delete files — single or batch via paths[] |
| 4 | SearchTool |
observe | Smart search: query expansion, fuzzy regex, Levenshtein fallback, auto-expand ≤10 files |
| 5 | ListTool |
observe | List directory contents |
| 6 | TreeTool |
observe | Directory tree structure |
| 7 | EvalTool |
compute | JavaScript via Boa engine, file glob, workspace_date (feature eval) |
| 8 | ReadAllTool |
observe | Batch read all files in directory |
| 9 | MkDirTool |
act | Create directory (deferred) |
| 10 | MoveTool |
act | Move/rename file (deferred) |
| 11 | FindTool |
observe | Find files by name pattern (deferred) |
Quick start
Via sgr-agent (recommended)
= { = "0.7", = ["tools"] }
# with JS eval:
= { = "0.7", = ["tools-eval"] }
use ;
Standalone
= "0.1"
# with JS eval:
= { = "0.1", = ["eval"] }
Usage
use Arc;
use ;
// 1. Implement FileBackend for your runtime
;
// 2. Create tools
let backend = new;
let read = ReadTool;
let write = WriteTool;
let search = SearchTool;
let tree = TreeTool;
Adding your own tools
Build custom tools using sgr-agent-core types:
use Arc;
use ;
use JsonSchema;
use Deserialize;
use FileBackend;
;
Pattern: struct YourTool<B: FileBackend>(pub Arc<B>) — generic over backend, reusable across projects.
Middleware pattern (extending tools)
When you need project-specific behavior on top of base tools (workflow guards, hooks, annotations), use the middleware wrapper pattern instead of forking the tool:
use ;
use ;
/// Middleware: adds workflow tracking + content security scanning to ReadTool.
When to use middleware vs custom tool:
| Scenario | Approach |
|---|---|
| Add pre/post hooks to existing tool | Middleware wrapper |
| Same schema, different behavior | Middleware wrapper |
| Completely different schema/logic | Custom tool from scratch |
| Project-specific annotations (CRM, etc.) | Middleware wrapper |
Real example from PAC1 agent — 3 tools use middleware:
ReadTool+ security scan + workflow trackingWriteTool+ outbox injection + JSON schema validation + hooksDeleteTool+ workflow guards (block delete before write)
Design principles
Based on building a PAC1 benchmark agent (16→11 tools, 7 models, 40+ tasks) and studying Codex CLI / Claude Code:
- 7 core tools max in prompt schema — models degrade on long tool lists
- Deferred loading for rarely-used tools (mkdir, move, find)
- Trust metadata on every read:
[path | trusted/untrusted] - Batch tools justified only when saving 3+ round-trips (read_all: 48→4 calls)
- Smart search — don't fail silently, try name variants and fuzzy matching
- JSON auto-repair — LLMs produce broken JSON, fix it before writing
Crate architecture
sgr-agent-core ← Tool trait, AgentContext, schema (5 lightweight deps)
↑ ↑
sgr-agent-tools sgr-agent
(this crate) (framework, re-exports tools via feature "tools")
Features
| Feature | Default | What |
|---|---|---|
| (none) | yes | 10 tools without JS eval |
eval |
no | Adds EvalTool — Boa JS engine (~5MB binary size) |