openclaw-langcache
v1.0.2
Published
Semantic caching skill for OpenClaw using Redis LangCache
Downloads
681
Maintainers
Readme
@openclaw/langcache
Semantic caching skill for OpenClaw using Redis LangCache.
Reduce LLM costs and latency by caching responses for semantically similar queries, with built-in privacy and security guardrails.
Features
- Semantic similarity matching - Cache hits for similar (not just identical) queries
- Hard block enforcement - Automatically blocks caching of sensitive data:
- Temporal info (today, tomorrow, deadlines, appointments)
- Credentials (API keys, passwords, tokens, OTP)
- Identifiers (emails, phone numbers, account IDs)
- Personal context (relationships, private conversations)
- Category-aware thresholds - Different similarity thresholds for factual Q&A vs style transforms
- CLI and Python integration - Use from shell scripts or embed in Python agents
Installation
Via npm (Recommended)
npm install openclaw-langcacheThe skill will be automatically installed to your OpenClaw workspace.
Via Git
git clone https://github.com/openclaw/langcache.git ~/.openclaw/workspace/skills/langcacheManual
Download and extract to ~/.openclaw/workspace/skills/langcache/
Configuration
Add your Redis LangCache credentials to ~/.openclaw/secrets.env:
LANGCACHE_HOST=your-instance.redis.cloud
LANGCACHE_CACHE_ID=your-cache-id
LANGCACHE_API_KEY=your-api-keyGet these from Redis Cloud Console after creating a LangCache instance.
Usage
Automatic (via OpenClaw agent)
The skill triggers automatically when you mention:
- "cache LLM responses"
- "semantic caching"
- "reduce API costs"
- "configure LangCache"
CLI
# Search for cached response
langcache.sh search "What is Redis?"
# With similarity threshold
langcache.sh search "What is Redis?" --threshold 0.9
# Store a response
langcache.sh store "What is Redis?" "Redis is an in-memory data store..."
# Check if content would be blocked
langcache.sh check "What's on my calendar today?"
# Output: BLOCKED: temporal_info
# Delete entries
langcache.sh delete --id <entry-id>
langcache.sh delete --attr model=gpt-4Python Integration
from examples.agent_integration import CachedAgent, CacheConfig
agent = CachedAgent(config=CacheConfig(
enabled=True,
model_id="gpt-5",
))
# Automatically uses cache with policy enforcement
response = await agent.complete("What is semantic caching?")Caching Policy
Cacheable (white-list)
| Category | Examples | Threshold |
|----------|----------|-----------|
| Factual Q&A | "What is X?", "How does Y work?" | 0.90 |
| Definitions / docs | API docs, command help | 0.90 |
| Command explanations | "What does git rebase do?" | 0.92 |
| Reply templates | "polite no", "follow-up", "intro" | 0.88 |
| Style transforms | "make this warmer/shorter" | 0.85 |
Never Cached (hard blocks)
| Category | Examples | |----------|----------| | Temporal | today, tomorrow, deadline, ETA, "in 20 minutes" | | Credentials | API keys, passwords, tokens, OTP/2FA | | Identifiers | emails, phone numbers, account IDs, UUIDs | | Personal | "my wife said", private conversations, relationships |
File Structure
skills/langcache/
├── SKILL.md # Skill definition and instructions
├── scripts/
│ └── langcache.sh # CLI wrapper with policy enforcement
├── references/
│ ├── api-reference.md # Complete REST API documentation
│ └── best-practices.md # Optimization techniques
└── examples/
├── basic-caching.sh # Simple cache workflow
└── agent-integration.py # Python integration patternAPI Reference
See references/api-reference.md for complete REST API documentation.
Key Endpoints
| Endpoint | Method | Description |
|----------|--------|-------------|
| /v1/caches/{id}/entries/search | POST | Search for cached response |
| /v1/caches/{id}/entries | POST | Store new entry |
| /v1/caches/{id}/entries/{entryId} | DELETE | Delete by ID |
| /v1/caches/{id}/flush | POST | Clear all entries |
Requirements
- OpenClaw 2024.1.0+
- Redis Cloud account with LangCache enabled
- Node.js 18+ (for npm installation)
jqandcurl(for CLI usage)
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT License - see LICENSE for details.
