The Wizard of AI
Back to Resources
Complete Guide5B+ Tokens of Experience

The OpenClaw Mastery Guide

Everything we learned from 5 billion tokens of real-world Claude Code automation. 12 chapters covering architecture, security, CRM intelligence, cost optimization, and the exact prompts to build each system.

45 min read
12 chapters
Ready-to-use prompts
Free Download

Get the Full Guide as a PDF

All 12 chapters, every prompt, and the complete architecture diagrams — formatted for offline reading and team sharing.

Plus: bonus prompts not included on this page.

System Architecture

How all 12 systems connect to form your AI employee

Gmail Inbox
Calendar
Slack/Telegram
Web Content
6-Layer Security Gate

Sanitize → Quarantine → Frontier Scan → Score

AI Agent Core

Rubric Scoring + CRM Intelligence + Knowledge Base + Meeting Analysis

Opus 4.6
Sonnet 4.6
Local Embed
CRM + SQLite
HubSpot Sync
Telegram Alerts
Encrypted Backup
01

Make It a Full-Time Employee

Give your agent its own identity, email, and workspace account so it operates as a legitimate team member.

Create a dedicated email address and workspace identity
Route public-facing emails (sponsorships, support) directly to your agent
Let it draft context-aware replies — not templates, real personalized emails
Use a humanizer skill so nothing smells like AI
Connect to your CRM (HubSpot, Salesforce) for automatic deal stage tracking
Ready-to-Use Prompt

Build a sponsor inbox pipeline with multi-account email support. Create per-account config JSON files with sender identity, rubric weights, and CRM mapping. Set up a cron job every 10 minutes using Go CLI for Gmail API access. Implement lazy backfill to fetch historical threads for new sender domains. For every inbound email: (1) quarantine in isolated sandbox, (2) run deterministic sanitizer for prompt injection patterns, (3) Frontier scan with best available model, (4) if clean, score against editable rubric with 5 dimensions — Fit, Clarity, Budget Signal, Seriousness, Company Trust — each weighted. Apply Gmail labels matching score tier. Track deal stage locally in SQLite AND sync to HubSpot via API. Draft context-aware replies using Opus 4.6 with humanizer skill — never send template responses. Research every sender: validate company website, check reviews, look up team members on LinkedIn. If confidence score < 60%, escalate to Telegram with full reasoning for human review. Store all scored emails with embeddings for future cross-reference with CRM and knowledge base.

02

Score Everything with Rubrics

Don't just read emails — score them. Build an editable rubric so your agent gets smarter every day.

5 dimensions: Fit, Clarity, Budget, Seriousness, Company Trust
Weighted scoring with tier-based actions (Exceptional → Low → Spam)
Low-confidence scores trigger human review via Telegram
Agent researches sender: validates company, checks reviews, looks up people
Constantly refine the rubric with feedback — it learns over time

Scoring Tiers & Actions

Exceptional (80+)Escalate to team immediately
High (60-79)Non-urgent team notification
Medium (40-59)Auto-reply with qualification questions
Low (20-39)Politely decline
Spam (<20)Ignore completely
Ready-to-Use Prompt

Create an editable email scoring rubric with 5 weighted dimensions: Fit (does this match our niche?), Clarity (is the ask specific?), Budget Signal (do they mention budget/deliverables?), Seriousness (professional tone, real company domain, not Gmail?), and Company Trust (verifiable web presence, reviews, team on LinkedIn?). Weight each dimension and compute a composite score 0-100. Define tier actions: Exceptional (80+) escalate to team immediately with Slack/Telegram alert, no auto-reply. High (60-79) notify team non-urgently. Medium (40-59) auto-reply with qualification questions. Low (20-39) politely decline with template. Spam (<20) ignore and log. When confidence is below 60%, send full breakdown to Telegram with reasoning and ask for human review. Store rubric as editable JSON so you can adjust weights based on feedback. Track score accuracy over time — log every human override and use it to retrain the rubric weekly.

03

Dual Prompt Stacks

Different models need different prompting styles. Maintain parallel prompt sets and sync them nightly.

Claude Opus: natural language, explain 'why' behind rules, no ALL CAPS
GPT/Codex: structured, ALL CAPS welcome, different formatting
Root folder = primary model, subfolder = backup model
Nightly sync review checks for drift between stacks
One-command model swap promotes the backup and demotes the primary
Ready-to-Use Prompt

Set up dual prompt stacks for multi-model resilience. Root markdown files are Claude-optimized: use natural language, explain the 'why' behind every rule, avoid ALL CAPS (Opus 4.6 overindexes on emphasis). Create a /codex-prompts subfolder with GPT/Codex-optimized versions of every file — structured format, ALL CAPS welcome, different formatting conventions. Download the official prompting guides for each model and reference them. Both stacks MUST contain identical operational facts — only the formatting and tone differ. Set up a nightly sync review cron: compare every file across stacks, flag any content drift (different facts, missing rules, contradicting instructions), and alert via Telegram if drift is detected. Build a one-command model swap: promote the backup folder to root, demote current root to subfolder, update all references. The longest your stacks should ever be out of sync is 24 hours.

04

The File Architecture

One file per concern. Zero duplication. Every piece of information has exactly one home.

agents.md — operational rules, security, cron standards, error reporting
soul — personality, philosophy (5-10 lines max)
user.md — who you are and your business context
tools — channel IDs, API references, environment values
memory.md — private learnings, never shared
PRD, use cases, security docs — loaded on demand, not every call

Core File Structure

agents.mdOperational behavior & security protocols
soulAgent personality & philosophy
user.mdUser profile & business context
toolsEnvironment values & integration IDs
heartbeatPeriodic health check cron
memory.mdPrivate accumulated knowledge
sub-agent policyHow to spawn sub-agents
Ready-to-Use Prompt

Set up a strict file architecture with zero duplication. Each file has exactly one purpose and every piece of information lives in exactly one place. agents.md — operational rules, security protocols, safety constraints, task execution patterns, message formatting, cron standards, error reporting procedures. Define both 'what belongs here' and 'what does NOT belong here' for each file. soul — agent personality, philosophy, identity (name, creature type, emoji), keep to 5-10 lines max per OpenClaw best practices. user.md — everything about you: name, role, business context, communication preferences, timezone, team structure. tools — environment-specific values only: Telegram channel IDs, Slack workspace IDs, Asana project IDs, API endpoint URLs. Never put these in other files. heartbeat — periodic health check cron configuration. memory.md — private accumulated learnings, never shared with team or external. sub-agent policy — rules for spawning sub-agents, which model to use, context limits, permission boundaries. On-demand docs (loaded only when needed, NOT every call): PRD (full feature definitions), use cases, workspace files, security best practices, coding standards, skill files, reference material. Run an automated cron to detect duplication across files and prune by ~10% every other day.

05

CRM Intelligence

Scan Gmail, calendar, and Slack — auto-discover contacts, reject spam, and build a living database.

Auto-discover contacts from email + calendar (reject spam, marketing, events)
SQL database with vector column — traditional queries AND semantic search
Proactive company research: daily news/article scans for all CRM contacts
Natural language queries: 'Who haven't I talked to in 4 months?'
Cross-pollination: agent connects sponsor emails to knowledge base articles
Auto follow-ups, nudges, and relationship summaries
Ready-to-Use Prompt

Build a contact discovery pipeline that scans Gmail, Google Calendar, and Slack daily. For every new contact found: filter out spam, marketing emails, event invites, and automated notifications. Classify remaining contacts and store in a SQLite database with a vector column — support both traditional SQL queries AND semantic/natural language search using local embeddings (Nomic MBEG, zero cost). Run proactive company research daily: search for news articles, press releases, and social mentions about every CRM company. Enable natural language queries like 'Who haven't I talked to in 4 months?' or 'Show me all contacts at Series A companies.' Implement cross-pollination: when a new sponsor email arrives, automatically cross-reference against the knowledge base for related articles, previous conversations, and company intelligence. Generate auto follow-up drafts, relationship nudges, and weekly relationship summaries. Back up the CRM database encrypted to Google Drive nightly.

06

Meeting Intelligence

Every meeting → transcript → action items → CRM update → assigned to the right person automatically.

Fathom notetaker transcribes every meeting (internal + external)
Pull transcript via API after meeting ends
Match attendees to CRM contacts automatically
Extract insights AND action items
Action items → Telegram for approval → Todoist + HubSpot
Auto-assign action items to correct person and deal
Ready-to-Use Prompt

Build a meeting intelligence pipeline. Use Fathom notetaker to transcribe every meeting (internal + external). After each meeting ends, pull the transcript via Fathom API. Match all attendees to existing CRM contacts by email/name. Extract two categories: (1) strategic insights and key discussion points, (2) specific action items with assignee and deadline. Generate context embeddings using local Nomic model and store alongside the CRM record. For action items: send to Telegram for human approval before creating tasks. On approval, create Todoist tasks AND update HubSpot — automatically associate each action item to the correct deal and assign to the right team member based on meeting context. Track follow-through: if an action item isn't completed within the deadline, send a nudge.

07

Knowledge Base & Content Pipeline

Everything you read, save, or share gets chunked, embedded, and cross-referenced automatically.

Drop articles, videos, X posts into Telegram → auto-saved with summary
Cross-post to team's Slack channel with attribution
Daily proactive search for news about CRM companies
Sanitize → sandbox → Frontier scan all ingested content
Chunk, embed, store in SQLite with semantic search
Tag @Claude in Slack: 'potential video idea' → auto-creates Asana card with outline
Ready-to-Use Prompt

Build a knowledge base ingestion pipeline. Accept input from Telegram (forward any article/video/tweet) and Slack (@Claude save command). For every ingested item: (1) pre-flight URL validation, (2) fetch full content, (3) sanitize — strip scripts, iframes, tracking pixels, (4) quarantine in isolated sandbox, (5) Frontier scan with best model to check for prompt injection or malicious content, (6) if safe, chunk into semantic segments, (7) embed locally with Nomic MBEG (zero cost), (8) store in SQLite with full-text search + vector search. Cross-post saved items to team Slack AI-trends channel with attribution. Run a daily proactive search cron: for every company in the CRM, search for new articles, news, and social mentions — auto-save relevant ones. Enable semantic querying: 'Find articles about AI agents in healthcare' returns ranked results with sources. For content pipeline: when someone tags @Claude with 'potential video idea', read the full thread context, query the knowledge base, search X/Twitter for viral discourse on the topic, then create a structured Asana card with outline, hook ideas, thumbnail concepts, and reference links.

08

6-Layer Security Architecture

The #1 concern with AI agents touching real data. Here's how to lock it down properly.

Layer 1: Network gateway hardening — token auth, never exposed to internet
Layer 2: Channel access control — DM = full info, group = redacted, email = strictest
Layer 3: 3-layer prompt injection defense (deterministic + Frontier scanner + risk scoring)
Layer 4: Secret protection — outbound PII redaction, pre-commit hooks
Layer 5: Nightly security council — automated audits of permissions, configs, secrets
Layer 6: Encrypted databases, password-protected backups, data classification tiers
1

Network Gateway

Token auth, never exposed directly

2

Channel Control

DM, group, email access tiers

3

Prompt Injection Defense

Deterministic + AI scanner + risk markers

4

Secret Protection

Outbound redaction on all paths

5

Automated Reviews

Nightly council scans everything

6

Data Encryption

Encrypted DBs + classified data tiers

Ready-to-Use Prompt

Implement a 6-layer security architecture for your AI agent system. Layer 1 — Network Gateway: token-based authentication on all endpoints, never expose the agent directly to the internet, weekly verification via heartbeat cron. Layer 2 — Channel Access Control: define 3 tiers — DM (full access, confidential data OK), Group Chat (redacted, internal only), Email (strictest, no PII ever). Layer 3 — 3-stage Prompt Injection Defense: (a) deterministic sanitizer that strips known injection patterns like 'ignore previous instructions', (b) Frontier scanner — take the best model, sandbox the content, have it scan for adversarial intent, (c) elevated risk markers with cumulative scoring. Layer 4 — Secret Protection: outbound PII redaction on ALL message paths (Telegram, Slack, email), pre-commit git hook that blocks common API key patterns, locked file permissions. Layer 5 — Automated Reviews: nightly security council scans file permissions, gateway configs, secrets exposure, CRM data access patterns; offensive + defensive + data privacy + operational realism perspectives. Layer 6 — Data Encryption: encrypted SQLite databases, password-protected backups, data classification tiers (Confidential → Internal → Restricted → External) enforced per-conversation.

09

Smart Cron Scheduling

Spread heavy jobs overnight so you never blow your token quota during the day.

1:00 AM — Instagram analytics
1:15 AM — X/Twitter analytics
1:30 AM — YouTube analytics
2:00 AM — CRM sync + company research
3:00 AM — Security council + platform council
Never compete with daytime usage for quota
Ready-to-Use Prompt

Set up smart cron scheduling to spread heavy jobs overnight and avoid competing with daytime quota. Schedule: 1:00 AM — Instagram analytics collection, 1:15 AM — X/Twitter analytics, 1:30 AM — YouTube analytics, 2:00 AM — CRM sync + proactive company research for all contacts, 2:30 AM — Knowledge base article discovery scan, 3:00 AM — Security council (file permissions, gateway configs, secrets audit), 3:20 AM — Platform council (code quality, cron health, test coverage, prompt quality, dependency check), 3:40 AM — Innovation scout (search web for new OpenClaw use cases, compare with current setup, suggest improvements). Use calendar-aware polling — only pull data when signals indicate change. Monitor the 5-hour token window and ensure heavy crons never overlap with peak daytime usage. Log all cron executions and alert via Telegram on any failures.

10

Logging & Self-Healing

Log everything. Every morning, say 'look at the logs and fix issues.' That's it.

Single event-log.js pattern shared across entire app
JSONL backup + database storage with rotation
learnings.md, errors.md, feature-request.md — accumulated knowledge
Morning routine: 'Look at overnight logs, fix any issues'
Nightly councils: Platform (code quality, cron health), Security, Innovation Scout
Innovation Scout searches web for new use cases and suggests improvements
Ready-to-Use Prompt

Build a comprehensive logging and self-healing system. Create a single event-log.js pattern shared across the entire app — every LLM call, external API request, cron execution, error, and user interaction gets logged. Store in two formats: JSONL file backup (rotated daily) + SQLite database with full-text search. Maintain 3 accumulating knowledge files: learnings.md (patterns discovered, optimizations found), errors.md (recurring issues and their fixes), feature-request.md (ideas from daily use). Set up 3 nightly councils: (1) Platform Council — reviews cron health, code quality, test coverage, prompt quality, dependency versions, storage usage, skill integrity, config consistency, CRM data integrity; (2) Security Council — offensive, defensive, data privacy, and operational realism perspectives; (3) Innovation Scout — searches the web for new OpenClaw use cases, compares with your current setup, suggests improvements with implementation plans. Morning routine: say 'Look at overnight logs and fix any issues' — the agent reads all error logs, cross-references with learnings.md, and auto-fixes known patterns.

11

Cost Optimization

Run 5 billion tokens worth of automation without going broke.

Local embeddings (Nomic MBEG) — zero cost vs cloud APIs
Model tiering: Sonnet for daily tasks, Opus for complex reasoning
Spread usage throughout the day — avoid quota spikes
Prompt caching (built-in, saves 50%+ on repeated contexts)
Calendar-aware polling — only pull data when signals indicate change
Notification batching: Critical = instant, High = hourly, Medium = 3h
Ready-to-Use Prompt

Implement cost optimization for high-volume AI agent usage. (1) Local embeddings: use Nomic MBEG text model on-device — zero cost vs cloud embedding APIs. (2) Model tiering: Sonnet 4.6 for daily tasks (rubric scoring, email drafts, cron jobs), Opus 4.6 for complex reasoning (security analysis, architecture decisions, multi-step planning). Route via a centralized LLM-router.js. (3) Spread usage: schedule heavy jobs overnight across a 5-hour window, never compete with daytime interactive usage. (4) Prompt caching: built into Claude — saves 50%+ on repeated system prompts. Monitor cache hit rate via /status command. (5) Calendar-aware polling: don't pull data on a fixed schedule — look for signals that indicate change (new email, calendar event ending, Slack mention). (6) Notification batching: Critical = deliver immediately, High = batch hourly (CRM updates, council digests, cron failures), Medium = batch every 3 hours (routine updates). (7) Track everything: build an LLM usage dashboard that logs every call — model, input/output tokens, estimated cost, which feature triggered it. Query with 'Show me LLM usage for the last 24 hours' to identify optimization opportunities.

12

Backup & Disaster Recovery

If your machine dies tomorrow, you can restore everything in minutes.

Auto-discover database files → encrypt → upload to Google Drive
Hourly git sync: auto-commit + push to GitHub + Telegram alert
Documented restoration process: download → decrypt → restore
Password-protected database backups (even if someone finds them)
Ready-to-Use Prompt

Build a backup and disaster recovery system. (1) Auto-discover all database files across the project. (2) Encrypt each database with AES-256 using a password stored in your secrets manager. (3) Upload encrypted backups to Google Drive via API — organize by date. (4) Rotate old backups: keep daily for 7 days, weekly for 4 weeks, monthly for 12 months. (5) Git sync: every hour, auto-commit any changed files, push to GitHub, send Telegram confirmation. (6) Document the full restoration process in a restore.md file: download from Google Drive → decrypt with stored password → read the manifest → restore database files → verify integrity → restart all services. (7) Password-protect all database backups — even if someone finds the file, they can't read it without the encryption key. (8) Test the restore process monthly: spin up a fresh environment, run the restore, verify all data is intact and all services come online.

Want This Built For You?

Skip the learning curve. Our white-glove setup service builds your entire AI agent system — sponsor pipeline, CRM, security, cron jobs, and more — in 2-4 weeks.

White-Glove Setup