Token Reduction Engine
Deterministic AI validation middleware. Catches hallucinations before they reach users. Zero LLM calls required for fact-based queries. Typical results: 20% token savings, 95%+ accuracy on facts.
Quick Reference
| Need | Command |
|---|
| Validate a response | python3 scripts/hguard_client.py validate "query" "response" |
| Batch validate | python3 scripts/hguard_client.py batch <input.json> <output.json> |
| Check status | python3 scripts/hguard_client.py status |
Installation
clawhub install token-reduction-engine
Configuration
Add to your agent config:
{
"api_url": "http://localhost:8000"
}
Python API
# You must have the Brain API running at localhost:8000
from scripts.hguard_client import HGuardClient
client = HGuardClient()
# Validate any AI-generated text
result = client.validate("What is Docker?", "Docker is a containerization platform.")
print(result["valid"]) # True
print(result["confidence"]) # 1.0
# Check for hallucinations
bad = client.validate("What is Python recursion depth?", "Python recursion depth is 500.")
print(bad["valid"]) # False
print(bad["flags"]) # ["Factual mismatch: ..."]
Metrics
metrics = client.get_session_metrics()
print(f"Cache hit rate: {metrics['cache_hit_rate']}%")
print(f"Tokens saved: {metrics['tokens_saved']}")
print(f"Flags caught: {metrics['flags_caught']}")
Troubleshooting
| Issue | Fix |
|---|
| "Brain API not found" | Start the brain service at localhost:8000 |
| "No facts loaded" | Load facts via Brain API endpoint |
| Validation too strict | Adjust threshold in config |
Uninstall
clawhub uninstall token-reduction-engine
License
MIT-0 (Free, no attribution required)
Note
Requires a running Brain API instance. This skill provides the client only. The server component must be configured separately.