This is the companion post to What We Found Auditing OpenClaw. That post covered the why. This one covers the how — with code.
Three systems define what our fork does differently: a five-tier security model that replaces binary tool permissions, an LLM-powered sentiment analyzer that replaces keyword counting, and a style adaptation engine that learns how each user prefers to communicate. Each system was designed to degrade gracefully, cache aggressively, and never block the critical path.
Security Tiers: Five Named Levels
OpenClaw's original security model had two states: a tool was enabled or disabled. If you enabled the file-write tool, it could write anywhere. If you enabled http-request, it could hit any endpoint. No scoping. No per-tool constraints.
For a development CLI, that's reasonable. For a platform routing customer data through autonomous agents, it's a non-starter.
How the Tiers Work
SecurityTiers.ts exports five named configurations. Each tier is a frozen object specifying exactly what an agent can and cannot do:
export const SecurityTiers = {
dangerous: {
name: 'dangerous',
tools: { allow: '*', deny: [] },
network: { allow: '*', deny: [] },
filesystem: { allow: '*', deny: [] },
approval: 'none',
},
permissive: {
name: 'permissive',
tools: { allow: '*', deny: ['shell-exec', 'system-admin'] },
network: { allow: '*', deny: ['internal-*'] },
filesystem: { allow: ['workspace/**'], deny: ['**/.env', '**/secrets/**'] },
approval: 'destructive-only',
},
balanced: {
name: 'balanced',
tools: { allow: ['file-read', 'file-write', 'http-get', 'search', 'calendar'], deny: ['*'] },
network: { allow: ['api.openai.com', 'api.anthropic.com', '*.wunderland.sh'], deny: ['*'] },
filesystem: { allow: ['workspace/**'], deny: ['**/.env', '**/node_modules/**', '**/secrets/**'] },
approval: 'external-actions',
},
strict: {
name: 'strict',
tools: { allow: ['file-read', 'search'], deny: ['*'] },
network: { allow: [], deny: ['*'] },
filesystem: { allow: ['workspace/output/**'], deny: ['*'] },
approval: 'all-writes',
},
paranoid: {
name: 'paranoid',
tools: { allow: [], deny: ['*'] },
network: { allow: [], deny: ['*'] },
filesystem: { allow: [], deny: ['*'] },
approval: 'every-action',
},
} as const;
balanced is the default tier for agents built in Rabbit Hole. The agent can read and write files in the workspace, make HTTP requests to whitelisted domains, and use a curated set of tools. Everything else requires explicit approval.
paranoid is exactly what it sounds like. Every action — reading a file, making an API call, invoking a tool — queues for human approval. We use it for initial deployments where the client hasn't built trust with the agent yet.
Approval Workflows
The approval field determines when human review triggers:
| Value | Behavior |
|-------|----------|
| none | No approvals. Agent acts autonomously. |
| destructive-only | Approvals for delete, overwrite, and irreversible network calls |
| external-actions | Approvals for any action leaving the local environment |
| all-writes | Approvals for any write operation (file, network, database) |
| every-action | Approvals for everything |
The approval queue integrates with the Rabbit Hole dashboard. Pending approvals show as cards with full context — what the agent wants to do, why, and what data it would touch. One-click approve or reject.
Sentiment Analysis: Beyond Keywords
OpenClaw's original sentiment implementation was a function that counted positive and negative words in a dictionary. It worked for detecting "I'm angry" and "This is great." It failed spectacularly on everything else.
Consider: "Oh, wonderful. Another AI that can't read my calendar." That's negative sentiment wrapped in positive vocabulary. Keyword matching scores it as positive. Any human reads it as frustrated sarcasm.
Architecture
LLMSentimentAnalyzer.ts routes messages through the cheapest available LLM with a structured prompt:
const SENTIMENT_PROMPT = `Analyze the emotional tone of this message.
Return JSON: { "sentiment": "positive"|"negative"|"neutral"|"frustrated"|"confused",
"confidence": 0.0-1.0, "escalation_risk": "low"|"medium"|"high" }
Message: "{message}"`;
Three design decisions make this practical rather than expensive:
LRU Cache
An in-memory LRU cache (1,000 entries, configurable) stores message → sentiment mappings. Customer support conversations repeat. "How do I reset my password?" hits the same sentiment every time. Cache hit rate in production hovers around 40% — that's 40% of sentiment calls that cost nothing.
class LLMSentimentAnalyzer {
private cache: LRUCache<string, SentimentResult>;
private limiter: ConcurrencyLimiter;
async analyze(message: string): Promise<SentimentResult> {
const cached = this.cache.get(message);
if (cached) return cached;
return this.limiter.run(async () => {
const result = await this.callLLM(message);
this.cache.set(message, result);
return result;
});
}
}
SmallModelResolver
Instead of burning GPT-4 tokens on sentiment classification, SmallModelResolver maps each provider to its cheapest model:
| Provider | Small Model | |----------|------------| | OpenAI | gpt-4o-mini | | Anthropic | claude-haiku | | Google | gemini-flash | | Mistral | mistral-small | | Groq | llama-3-8b |
The resolver checks which provider the agent is configured with and picks the cheapest option. Sentiment analysis costs drop to fractions of a cent per message.
Keyword Fallback
If no LLM provider is available — a self-hosted Ollama deployment went down, API key expired, network outage — the analyzer falls back to the original keyword approach. Degraded accuracy, but the agent never blocks waiting for sentiment. The fallback is the floor, not the ceiling.
Style Adaptation: Learning How You Communicate
Every person has a communication style. Some write three-word Slack messages. Others write paragraphs with bullet points. Some expect technical precision. Others want plain English.
Static agent personalities handle this with a prompt like "be concise and professional." That's a blunt instrument. It makes the agent sound the same to everyone, which means it sounds wrong to most people.
Three Axes
StyleAdaptation.ts tracks three independent dimensions:
Formality — casual ("hey, can you check...") to professional ("Could you please review..."). Measured on a 0–1 scale from the user's message history.
Verbosity — terse (one-line answers preferred) to detailed (full explanations with context). Measured by average message length and how often the user asks follow-up questions after short answers.
Technicality — plain language ("make the button blue") to expert jargon ("update the primary CTA's background-color to #2563eb"). Measured by vocabulary complexity and domain-specific term usage.
How It Learns
Each user interaction updates a running weighted average. Recent messages carry more weight than old ones (exponential decay with a half-life of 50 messages). The system doesn't need a training phase — it starts with the agent's default style and shifts within 5–10 messages.
interface StyleProfile {
formality: number; // 0 (casual) to 1 (formal)
verbosity: number; // 0 (terse) to 1 (detailed)
technicality: number; // 0 (plain) to 1 (expert)
confidence: number; // how many messages we've seen
}
The profile feeds into prompt assembly. A user with { formality: 0.2, verbosity: 0.8, technicality: 0.9 } gets responses that are casual, thorough, and technically precise. A user at { formality: 0.8, verbosity: 0.3, technicality: 0.2 } gets responses that are professional, brief, and jargon-free.
Why Not Just Ask?
We considered adding a settings page: "How formal should your agent be? How detailed?" Two reasons we didn't.
First, most people don't know how to answer that question. They know when a response feels wrong, but they can't articulate why in advance. Style preferences are revealed, not declared.
Second, preferences drift. The same person communicates differently on Monday morning versus Friday afternoon. A settings page captures a snapshot. Style adaptation captures the trajectory.
Putting It All Together
These three systems interact. A frustrated user (detected by sentiment) in strict mode (enforced by security tier) who prefers terse technical responses (learned by style adaptation) gets a different experience than a happy user in permissive mode who likes detailed plain-language explanations.
The agent doesn't just know what it can do. It knows how carefully to act, how the user feels, and how to say what it says.
That's what the audit bought us. Not just hardened security — a framework that adapts to the people using it.
Discussion