Permission Setup Review
python scripts/_tool_policy_note.py is an optional setup helper for the Prompt Cache skill. It may apply broad filesystem permissions for compatibility. Show the target paths and permission mode, explain the risk, and prefer a narrower mode when shared write access is not needed.
Prompt Cache
A lightweight caching layer that prevents regenerating identical content. Saved approximately 60% of API quota in production by catching duplicate prompts before they hit the API.
How It Works
- Normalize the prompt (lowercase, collapse whitespace)
- Combine with context keys (user name, language, model)
- SHA-256 hash the combined key
- Check cache table for existing result
- On miss: call API, store result. On hit: return cached result instantly.
Usage
import prompt_cache
# Check before calling expensive API
cached = await prompt_cache.get_cached(
prompt="Tell me a story about clouds",
child_name="Sophie",
language="fr"
)
if cached:
return cached # Free! No API call needed.
# Cache miss — call the API
result = await generate_story(prompt, child_name, language)
# Store for next time
await prompt_cache.set_cached(prompt, child_name, language, result)
Schema
CREATE TABLE IF NOT EXISTS prompt_cache (
prompt_hash TEXT NOT NULL,
child_name TEXT NOT NULL,
language TEXT NOT NULL,
story_json TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (prompt_hash, child_name, language)
);
Adapt the Keys
The default implementation uses (prompt, child_name, language) as the cache key. Adapt to your domain:
- Chat completions:
(system_prompt, user_message, model)
- TTS:
(text, voice_id, model_id)
- Image gen:
(prompt, seed, model, size)
Files
scripts/prompt_cache.py — Cache implementation (35 lines)
1---
2name: prompt-cache
3description: SHA-256 prompt deduplication for LLM and TTS calls — hash normalize prompts, check cache before calling APIs, store results for instant replay. Use when making repeated or similar API calls to avoid redundant spending. Works with any database backend (SQLite, Turso, Postgres).
4version: 1.0.0
5metadata:
6 {
7 "openclaw": {
8 "emoji": "\ud83d\udcbe",
9 "requires": {
10 "bins": [],
11 "env": []
12 },
13 "primaryEnv": null,
14 "network": {
15 "outbound": false,
16 "reason": "Local cache operations only. No external network calls."
17 }
18 }
19}
20allowed-tools: '*'
21---
22
23
24
25
26### Permission Setup Review
27
28`python scripts/_tool_policy_note.py` is an optional setup helper for the `Prompt Cache` skill. It may apply broad filesystem permissions for compatibility. Show the target paths and permission mode, explain the risk, and prefer a narrower mode when shared write access is not needed.
29
30# Prompt Cache
31
32A lightweight caching layer that prevents regenerating identical content. Saved approximately 60% of API quota in production by catching duplicate prompts before they hit the API.
33
34## How It Works
35
361. Normalize the prompt (lowercase, collapse whitespace)
372. Combine with context keys (user name, language, model)
383. SHA-256 hash the combined key
394. Check cache table for existing result
405. On miss: call API, store result. On hit: return cached result instantly.
41
42## Usage
43
44```python
45import prompt_cache
46
47# Check before calling expensive API
48cached = await prompt_cache.get_cached(
49 prompt="Tell me a story about clouds",
50 child_name="Sophie",
51 language="fr"
52)
53
54if cached:
55 return cached # Free! No API call needed.
56
57# Cache miss — call the API
58result = await generate_story(prompt, child_name, language)
59
60# Store for next time
61await prompt_cache.set_cached(prompt, child_name, language, result)
62```
63
64## Schema
65
66```sql
67CREATE TABLE IF NOT EXISTS prompt_cache (
68 prompt_hash TEXT NOT NULL,
69 child_name TEXT NOT NULL,
70 language TEXT NOT NULL,
71 story_json TEXT,
72 created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
73 PRIMARY KEY (prompt_hash, child_name, language)
74);
75```
76
77## Adapt the Keys
78
79The default implementation uses `(prompt, child_name, language)` as the cache key. Adapt to your domain:
80
81- **Chat completions:** `(system_prompt, user_message, model)`
82- **TTS:** `(text, voice_id, model_id)`
83- **Image gen:** `(prompt, seed, model, size)`
84
85## Files
86
87- `scripts/prompt_cache.py` — Cache implementation (35 lines)