openclaw-langcache 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenClaw Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @openclaw/langcache
2
+
3
+ Semantic caching skill for [OpenClaw](https://openclaw.ai) using [Redis LangCache](https://redis.io/langcache/).
4
+
5
+ Reduce LLM costs and latency by caching responses for semantically similar queries, with built-in privacy and security guardrails.
6
+
7
+ ## Features
8
+
9
+ - **Semantic similarity matching** - Cache hits for similar (not just identical) queries
10
+ - **Hard block enforcement** - Automatically blocks caching of sensitive data:
11
+ - Temporal info (today, tomorrow, deadlines, appointments)
12
+ - Credentials (API keys, passwords, tokens, OTP)
13
+ - Identifiers (emails, phone numbers, account IDs)
14
+ - Personal context (relationships, private conversations)
15
+ - **Category-aware thresholds** - Different similarity thresholds for factual Q&A vs style transforms
16
+ - **CLI and Python integration** - Use from shell scripts or embed in Python agents
17
+
18
+ ## Installation
19
+
20
+ ### Via npm (Recommended)
21
+
22
+ ```bash
23
+ npm install @openclaw/langcache
24
+ ```
25
+
26
+ The skill will be automatically installed to your OpenClaw workspace.
27
+
28
+ ### Via Git
29
+
30
+ ```bash
31
+ git clone https://github.com/openclaw/langcache.git ~/.openclaw/workspace/skills/langcache
32
+ ```
33
+
34
+ ### Manual
35
+
36
+ Download and extract to `~/.openclaw/workspace/skills/langcache/`
37
+
38
+ ## Configuration
39
+
40
+ Add your Redis LangCache credentials to `~/.openclaw/secrets.env`:
41
+
42
+ ```bash
43
+ LANGCACHE_HOST=your-instance.redis.cloud
44
+ LANGCACHE_CACHE_ID=your-cache-id
45
+ LANGCACHE_API_KEY=your-api-key
46
+ ```
47
+
48
+ Get these from [Redis Cloud Console](https://app.redislabs.com/) after creating a LangCache instance.
49
+
50
+ ## Usage
51
+
52
+ ### Automatic (via OpenClaw agent)
53
+
54
+ The skill triggers automatically when you mention:
55
+ - "cache LLM responses"
56
+ - "semantic caching"
57
+ - "reduce API costs"
58
+ - "configure LangCache"
59
+
60
+ ### CLI
61
+
62
+ ```bash
63
+ # Search for cached response
64
+ langcache.sh search "What is Redis?"
65
+
66
+ # With similarity threshold
67
+ langcache.sh search "What is Redis?" --threshold 0.9
68
+
69
+ # Store a response
70
+ langcache.sh store "What is Redis?" "Redis is an in-memory data store..."
71
+
72
+ # Check if content would be blocked
73
+ langcache.sh check "What's on my calendar today?"
74
+ # Output: BLOCKED: temporal_info
75
+
76
+ # Delete entries
77
+ langcache.sh delete --id <entry-id>
78
+ langcache.sh delete --attr model=gpt-4
79
+ ```
80
+
81
+ ### Python Integration
82
+
83
+ ```python
84
+ from examples.agent_integration import CachedAgent, CacheConfig
85
+
86
+ agent = CachedAgent(config=CacheConfig(
87
+ enabled=True,
88
+ model_id="gpt-5",
89
+ ))
90
+
91
+ # Automatically uses cache with policy enforcement
92
+ response = await agent.complete("What is semantic caching?")
93
+ ```
94
+
95
+ ## Caching Policy
96
+
97
+ ### Cacheable (white-list)
98
+
99
+ | Category | Examples | Threshold |
100
+ |----------|----------|-----------|
101
+ | Factual Q&A | "What is X?", "How does Y work?" | 0.90 |
102
+ | Definitions / docs | API docs, command help | 0.90 |
103
+ | Command explanations | "What does `git rebase` do?" | 0.92 |
104
+ | Reply templates | "polite no", "follow-up", "intro" | 0.88 |
105
+ | Style transforms | "make this warmer/shorter" | 0.85 |
106
+
107
+ ### Never Cached (hard blocks)
108
+
109
+ | Category | Examples |
110
+ |----------|----------|
111
+ | Temporal | today, tomorrow, deadline, ETA, "in 20 minutes" |
112
+ | Credentials | API keys, passwords, tokens, OTP/2FA |
113
+ | Identifiers | emails, phone numbers, account IDs, UUIDs |
114
+ | Personal | "my wife said", private conversations, relationships |
115
+
116
+ ## File Structure
117
+
118
+ ```
119
+ skills/langcache/
120
+ ├── SKILL.md # Skill definition and instructions
121
+ ├── scripts/
122
+ │ └── langcache.sh # CLI wrapper with policy enforcement
123
+ ├── references/
124
+ │ ├── api-reference.md # Complete REST API documentation
125
+ │ └── best-practices.md # Optimization techniques
126
+ └── examples/
127
+ ├── basic-caching.sh # Simple cache workflow
128
+ └── agent-integration.py # Python integration pattern
129
+ ```
130
+
131
+ ## API Reference
132
+
133
+ See [references/api-reference.md](skills/langcache/references/api-reference.md) for complete REST API documentation.
134
+
135
+ ### Key Endpoints
136
+
137
+ | Endpoint | Method | Description |
138
+ |----------|--------|-------------|
139
+ | `/v1/caches/{id}/entries/search` | POST | Search for cached response |
140
+ | `/v1/caches/{id}/entries` | POST | Store new entry |
141
+ | `/v1/caches/{id}/entries/{entryId}` | DELETE | Delete by ID |
142
+ | `/v1/caches/{id}/flush` | POST | Clear all entries |
143
+
144
+ ## Requirements
145
+
146
+ - OpenClaw 2024.1.0+
147
+ - Redis Cloud account with LangCache enabled
148
+ - Node.js 18+ (for npm installation)
149
+ - `jq` and `curl` (for CLI usage)
150
+
151
+ ## Contributing
152
+
153
+ 1. Fork the repository
154
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
155
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
156
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
157
+ 5. Open a Pull Request
158
+
159
+ ## License
160
+
161
+ MIT License - see [LICENSE](LICENSE) for details.
162
+
163
+ ## Resources
164
+
165
+ - [Redis LangCache Documentation](https://redis.io/docs/latest/develop/ai/langcache/)
166
+ - [OpenClaw Documentation](https://docs.openclaw.ai)
167
+ - [Semantic Caching Guide](https://redis.io/blog/what-is-semantic-caching/)
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "openclaw-langcache",
3
+ "version": "1.0.0",
4
+ "description": "Semantic caching skill for OpenClaw using Redis LangCache",
5
+ "keywords": [
6
+ "openclaw",
7
+ "skill",
8
+ "langcache",
9
+ "redis",
10
+ "semantic-caching",
11
+ "llm",
12
+ "ai",
13
+ "cache"
14
+ ],
15
+ "homepage": "https://github.com/openclaw/langcache#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/openclaw/langcache/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/openclaw/langcache.git"
22
+ },
23
+ "license": "MIT",
24
+ "author": {
25
+ "name": "OpenClaw Contributors"
26
+ },
27
+ "files": [
28
+ "skills/",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "scripts": {
33
+ "postinstall": "node scripts/postinstall.js"
34
+ },
35
+ "engines": {
36
+ "node": ">=18.0.0"
37
+ },
38
+ "openclaw": {
39
+ "type": "skill",
40
+ "skills": [
41
+ "langcache"
42
+ ],
43
+ "installPath": "skills/"
44
+ }
45
+ }
@@ -0,0 +1,187 @@
1
+ ---
2
+ name: langcache
3
+ description: This skill should be used when the user asks to "enable semantic caching", "cache LLM responses", "reduce API costs", "speed up AI responses", "configure LangCache", "search the semantic cache", "store responses in cache", or mentions Redis LangCache, semantic similarity caching, or LLM response caching. Provides integration with Redis LangCache managed service for semantic caching of prompts and responses.
4
+ version: 1.0.0
5
+ tools: Read, Bash, WebFetch
6
+ ---
7
+
8
+ # Redis LangCache Semantic Caching
9
+
10
+ This skill integrates Redis LangCache, a fully-managed semantic caching service, into OpenClaw workflows. LangCache stores LLM prompts and responses, returning cached results for semantically similar queries to reduce costs and latency.
11
+
12
+ ## Prerequisites
13
+
14
+ Before using LangCache, ensure the following environment variables are configured:
15
+
16
+ ```bash
17
+ LANGCACHE_HOST=<your-langcache-host>
18
+ LANGCACHE_CACHE_ID=<your-cache-id>
19
+ LANGCACHE_API_KEY=<your-api-key>
20
+ ```
21
+
22
+ Store these in `~/.openclaw/secrets.env` or configure them in the OpenClaw settings.
23
+
24
+ ## Core Operations
25
+
26
+ ### Search for Cached Response
27
+
28
+ Before calling an LLM, check if a semantically similar response exists:
29
+
30
+ ```bash
31
+ ./scripts/langcache.sh search "What is semantic caching?"
32
+ ```
33
+
34
+ With similarity threshold (0.0-1.0, higher = stricter match):
35
+
36
+ ```bash
37
+ ./scripts/langcache.sh search "What is semantic caching?" --threshold 0.95
38
+ ```
39
+
40
+ With attribute filtering:
41
+
42
+ ```bash
43
+ ./scripts/langcache.sh search "What is semantic caching?" --attr "model=gpt-5"
44
+ ```
45
+
46
+ ### Store New Response
47
+
48
+ After receiving an LLM response, cache it for future use:
49
+
50
+ ```bash
51
+ ./scripts/langcache.sh store "What is semantic caching?" "Semantic caching stores responses based on meaning similarity..."
52
+ ```
53
+
54
+ With attributes for filtering/organization:
55
+
56
+ ```bash
57
+ ./scripts/langcache.sh store "prompt" "response" --attr "model=gpt-5" --attr "user_id=123"
58
+ ```
59
+
60
+ ### Delete Cached Entries
61
+
62
+ By entry ID:
63
+
64
+ ```bash
65
+ ./scripts/langcache.sh delete --id "<entry-id>"
66
+ ```
67
+
68
+ By attributes:
69
+
70
+ ```bash
71
+ ./scripts/langcache.sh delete --attr "user_id=123"
72
+ ```
73
+
74
+ ### Flush Cache
75
+
76
+ Clear all entries (use with caution):
77
+
78
+ ```bash
79
+ ./scripts/langcache.sh flush
80
+ ```
81
+
82
+ ## Integration Pattern
83
+
84
+ The recommended pattern for integrating LangCache into agent workflows:
85
+
86
+ ```
87
+ 1. Receive user prompt
88
+ 2. Search LangCache for similar cached response
89
+ 3. If cache hit (similarity >= threshold):
90
+ - Return cached response immediately
91
+ - Log cache hit for observability
92
+ 4. If cache miss:
93
+ - Call LLM API
94
+ - Store prompt + response in LangCache
95
+ - Return LLM response
96
+ ```
97
+
98
+ ## Default Caching Policy
99
+
100
+ This policy is enforced automatically. All cache operations MUST respect these rules.
101
+
102
+ ### CACHEABLE (white-list)
103
+
104
+ | Category | Examples | Threshold |
105
+ |----------|----------|-----------|
106
+ | Factual Q&A | "What is X?", "How does Y work?" | 0.90 |
107
+ | Definitions / docs / help text | API docs, command help, explanations | 0.90 |
108
+ | Command explanations | "What does `git rebase` do?" | 0.92 |
109
+ | Reusable reply templates | "polite no", "follow-up", "scheduling", "intro" | 0.88 |
110
+ | Style transforms | "make this warmer/shorter/firmer" | 0.85 |
111
+ | Generic communication scripts | negotiation templates, professional responses | 0.88 |
112
+
113
+ ### NEVER CACHE (hard blocks)
114
+
115
+ These patterns are **blocked at the code level** - cache operations will refuse to store them.
116
+
117
+ | Category | Patterns to Detect | Reason |
118
+ |----------|-------------------|--------|
119
+ | **Temporal info** | today, tomorrow, this week, deadline, ETA, "in X minutes", appointments, schedules | Stale immediately |
120
+ | **Credentials** | API keys, tokens, passwords, OTP, 2FA codes, secrets | Security risk |
121
+ | **Identifiers** | phone numbers, emails, addresses, account IDs, order numbers, message IDs, chat IDs, JIDs | Privacy / PII |
122
+ | **Personal context** | names + relationships, private history, "who said what", specific conversations | Privacy / context-dependent |
123
+
124
+ ### Detection Patterns
125
+
126
+ The following regex patterns trigger a hard block:
127
+
128
+ ```
129
+ # Temporal
130
+ \b(today|tomorrow|tonight|yesterday)\b
131
+ \b(this|next|last)\s+(week|month|year|monday|tuesday|...)\b
132
+ \b(in\s+\d+\s+(minutes?|hours?|days?))\b
133
+ \b(deadline|eta|appointment|schedule[d]?)\b
134
+
135
+ # Credentials
136
+ \b(api[_-]?key|token|password|secret|otp|2fa)\b
137
+ \b(bearer|auth[orization]*)\s+\S+
138
+
139
+ # Identifiers
140
+ \b\d{10,}\b # phone numbers, long IDs
141
+ \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+ # emails
142
+ \b(order|account|message|chat)[_-]?id\b
143
+
144
+ # Personal context
145
+ \b(my\s+(wife|husband|partner|friend|boss|mom|dad|brother|sister))\b
146
+ \b(said\s+to\s+me|told\s+me|between\s+us)\b
147
+ ```
148
+
149
+ ### Attribute Strategies
150
+
151
+ Use attributes to partition the cache:
152
+
153
+ - `model`: LLM model used (useful when switching models)
154
+ - `category`: `factual`, `template`, `style`, `command`
155
+ - `skill`: Which skill generated the response
156
+ - `version`: API or prompt version
157
+
158
+ ## Search Strategies
159
+
160
+ LangCache supports two search strategies:
161
+
162
+ - **semantic** (default): Vector similarity matching
163
+ - **exact**: Case-insensitive exact match
164
+
165
+ Combine both for hybrid search:
166
+
167
+ ```bash
168
+ ./scripts/langcache.sh search "prompt" --strategy "exact,semantic"
169
+ ```
170
+
171
+ ## Observability
172
+
173
+ Monitor cache performance:
174
+ - Track hit/miss ratios
175
+ - Log similarity scores for hits
176
+ - Alert on high miss rates (may indicate threshold too high)
177
+ - Review stored entries periodically for relevance
178
+
179
+ ## References
180
+
181
+ - [API Reference](references/api-reference.md) - Complete REST API documentation
182
+ - [Best Practices](references/best-practices.md) - Optimization techniques
183
+
184
+ ## Examples
185
+
186
+ - [examples/basic-caching.sh](examples/basic-caching.sh) - Simple cache workflow
187
+ - [examples/agent-integration.py](examples/agent-integration.py) - Python integration pattern