OpenClaw Tool Pre-filter (openclaw-tool-prefilter)
September 20, 2026 Β· View on GitHub
Dynamic two-stage skill and tool pre-filtering plugin for OpenClaw, powered by Decision Models (such as Jev / TypeSafe).
π― The Problem
By default, an AI agent loads dozens of tool schemas and skill definitions on every single turn. This causes:
- Excess Context Bloat: 5,000β10,000+ tokens consumed per turn just for tool schemas.
- Higher Costs & Latency: Slower time-to-first-token (TTFT) and unnecessary API expenses.
- Tool Hallucinations: Conversational queries ("Hello", "Explain how quicksort works") risk triggering unrelated tools accidentally.
π‘ The Solution
openclaw-tool-prefilter hooks into the agent runtime at before_prompt_build:
User Turn
β
βΌ
[Decision Model: Jev / TypeSafe] ββ (Fast, ~40ms, <\$0.0001)
β
ββ Probability < threshold (e.g. Pure Chat) βββΊ Prune tool schemas (`toolsAllow: []`)
β β‘ Saves 5,000-10,000 tokens!
β
ββ Probability >= threshold (Action Needed) βββΊ Pass-through tools unconstrained
- Pure Conversation Optimization: Strips tool definitions when no actions are needed, saving thousands of tokens.
- Zero Hallucination: Eliminates unwanted tool calls on casual chit-chat, explanations, or code reviews.
- Bulletproof Fail-Open Safety: If the decision provider experiences network issues, rate limits, or timeouts, the plugin immediately fails open (no restrictions). Agent dialogue is never blocked.
- Compliant Request Boundaries: Correctly respects empty message inputs (e.g., image-only messages) without polluting context from historical prompt strings.
π¦ Installation
From ClawHub (Recommended)
openclaw plugins install clawhub:openclaw-tool-prefilter
From npm
openclaw plugins install npm:openclaw-tool-prefilter
From Local Source
git clone https://github.com/MertBasar0/openclaw-tool-prefilter.git
openclaw plugins install ./openclaw-tool-prefilter
βοΈ Configuration
In your openclaw.json or agent configuration:
{
"plugins": {
"tool-prefilter": {
"enabled": true,
"thresholdAnyTool": 0.35,
"timeoutMs": 500
}
}
}
Options
| Parameter | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable or disable pre-filtering. |
thresholdAnyTool | number | 0.35 | Probability threshold. Turns below this are treated as pure conversation. |
timeoutMs | number | 500 | Hard timeout for decision evaluation before failing open. |
π Token Savings Benchmark
| Scenario | Raw Context | With Tool Pre-filter | Savings |
|---|---|---|---|
| "NasΔ±lsΔ±n? BugΓΌn hava nasΔ±l?" | ~8,400 tokens | ~420 tokens | 95.0% |
| "Explain how raft consensus works" | ~9,200 tokens | ~580 tokens | 93.7% |
| "Git status kontrol et ve commit at" | ~8,900 tokens | ~8,900 tokens | Pass-through |
π§ͺ Testing & Verification
Run the automated test suite:
npm test
Build the distribution bundle:
npm run build
π License
MIT Β© Mert BaΕar