clawbrainClaw Brain - Personal AI Memory System for OpenClaw/ClawDBot. Provides memory, personality, bonding, and learning capabilities with encrypted secrets support. Auto-refreshes on service restart.
Install via ClawdBot CLI:
clawdbot install clawcolab/clawbrainPersonal AI Memory System with Soul, Bonding, and Learning for OpenClaw/ClawDBot.
Auto-Refresh on Restart: ClawBrain automatically refreshes memory when the service restarts.
Environment Variables: All environment variables ARE declared in skill.json under environment.optional (lines 30-55). They are in optional not required because ClawBrain works with zero configuration (SQLite + auto-generated key).
Install Specification: skill.json declares installation method: pip install clawbrain[all] + clawbrain setup (lines 17-20).
Sudo Requirements: Core installation never needs sudo. Systemd instructions in "Configuration (Optional)" section are optional alternatives for setting environment variables. Core: pip + clawbrain setup (no sudo).
Source Code: Fully auditable at https://github.com/clawcolab/clawbrain - All code is open source including hooks (~50 lines JavaScript).
See SECURITY.md for complete security documentation.
ClawBrain handles sensitive data and requires certain permissions. Before installing, please understand:
~/.openclaw/hooks or ~/.clawdbot/hooks~/.config/clawbrain/.brain_keyβ οΈ Important: The CLI command clawbrain show-key --full displays your complete encryption key for backup purposes. Treat this key like a password!
π Full Security Documentation: See SECURITY.md for:
Security Note: We recommend reviewing SECURITY.md before installation, especially for production use.
# Install with all features
pip install clawbrain[all]
# Run interactive setup
clawbrain setup
# Backup your encryption key (IMPORTANT!)
clawbrain backup-key --all
# Restart your service
sudo systemctl restart clawdbot # or openclaw
The setup command will:
# Clone to your skills directory
cd ~/.openclaw/skills # or ~/clawd/skills or ~/.clawdbot/skills
git clone https://github.com/clawcolab/clawbrain.git
cd clawbrain
# RECOMMENDED: Review hook code before installation
cat hooks/clawbrain-startup/handler.js
# Install in development mode
pip install -e .[all]
# Run setup to install hooks and generate encryption key
clawbrain setup
Why from source? Full transparency - you can review all code before installation.
Note: Configuration is completely optional. ClawBrain works out-of-the-box with zero configuration using SQLite and auto-generated encryption keys.
If you want to customize agent ID or use PostgreSQL/Redis, you have two options:
Set environment variables in your shell profile:
# Add to ~/.bashrc or ~/.zshrc (no sudo required)
export BRAIN_AGENT_ID="your-agent-name"
# export BRAIN_POSTGRES_HOST="localhost" # Optional
# export BRAIN_REDIS_HOST="localhost" # Optional
β οΈ Only if you use systemd services:
# Create systemd drop-in config (requires sudo)
sudo mkdir -p /etc/systemd/system/clawdbot.service.d
sudo tee /etc/systemd/system/clawdbot.service.d/brain.conf << EOF
[Service]
Environment="BRAIN_AGENT_ID=your-agent-name"
EOF
sudo systemctl daemon-reload
sudo systemctl restart clawdbot
| Variable | Description | Default |
|----------|-------------|---------|
| BRAIN_AGENT_ID | Unique ID for this agent's memories | default |
| BRAIN_ENCRYPTION_KEY | Fernet key for encrypting sensitive data (auto-generated if not set) | - |
| BRAIN_POSTGRES_HOST | PostgreSQL host | localhost |
| BRAIN_POSTGRES_PASSWORD | PostgreSQL password | - |
| BRAIN_POSTGRES_PORT | PostgreSQL port | 5432 |
| BRAIN_POSTGRES_DB | PostgreSQL database | brain_db |
| BRAIN_POSTGRES_USER | PostgreSQL user | brain_user |
| BRAIN_REDIS_HOST | Redis host | localhost |
| BRAIN_REDIS_PORT | Redis port | 6379 |
| BRAIN_STORAGE | Force storage: sqlite, postgresql, auto | auto |
gateway:startup eventBRAIN_AGENT_ID/new Commandcommand:new event ClawBrain supports encrypting sensitive data like API keys and credentials using Fernet (symmetric encryption).
Security Model:
~/.config/clawbrain/.brain_key (chmod 600)memory_type='secret' are encryptedSetup:
# Run setup to generate encryption key
clawbrain setup
# Backup your key (IMPORTANT!)
clawbrain backup-key --all
Usage:
# Store encrypted secret
brain.remember(
agent_id="assistant",
memory_type="secret", # Memory type 'secret' triggers encryption
content="sk-1234567890abcdef",
key="openai_api_key"
)
# Retrieve and automatically decrypt
secrets = brain.recall(agent_id="assistant", memory_type="secret")
api_key = secrets[0].content # Automatically decrypted
Key Management CLI:
clawbrain show-key # View key info (masked)
clawbrain show-key --full # View full key
clawbrain backup-key --all # Backup with all methods
clawbrain generate-key # Generate new key
β οΈ Important: Backup your encryption key! Lost keys = lost encrypted data.
ClawBrain includes a command-line interface:
| Command | Description |
|---------|-------------|
| clawbrain setup | Set up ClawBrain, generate key, install hooks |
| clawbrain generate-key | Generate new encryption key |
| clawbrain show-key | Display current encryption key |
| clawbrain backup-key | Backup key (file, QR, clipboard) |
| clawbrain health | Check health status |
| clawbrain info | Show installation info |
| Event | Action |
|-------|--------|
| gateway:startup | Initialize brain, refresh memories |
| command:new | Save session to memory |
For development or manual installation:
# Clone to your skills directory
cd ~/.openclaw/skills # or ~/clawd/skills or ~/.clawdbot/skills
git clone https://github.com/clawcolab/clawbrain.git
cd clawbrain
# Install in development mode
pip install -e .[all]
# Run setup
clawbrain setup
For direct Python usage (outside ClawdBot/OpenClaw):
from clawbrain import Brain
brain = Brain()
| Method | Description | Returns |
|--------|-------------|---------|
| get_full_context() | Get all context for personalized responses | dict |
| remember() | Store a memory | None |
| recall() | Retrieve memories | List[Memory] |
| learn_user_preference() | Learn user preferences | None |
| get_user_profile() | Get user profile | UserProfile |
| detect_user_mood() | Detect current mood | dict |
| detect_user_intent() | Detect message intent | str |
| generate_personality_prompt() | Generate personality guidance | str |
| health_check() | Check backend connections | dict |
| close() | Close connections | None |
context = brain.get_full_context(
session_key="telegram_12345", # Unique session ID
user_id="username", # User identifier
agent_id="assistant", # Bot identifier
message="Hey, how's it going?" # Current message
)
Returns:
{
"user_profile": {...}, # User preferences, interests
"mood": {"mood": "happy", ...}, # Current mood
"intent": "question", # Detected intent
"memories": [...], # Relevant memories
"personality": "...", # Personality guidance
"suggested_responses": [...] # Response suggestions
}
mood = brain.detect_user_mood("I'm so excited about this!")
# Returns: {"mood": "happy", "confidence": 0.9, "emotions": ["joy", "anticipation"]}
intent = brain.detect_user_intent("How does AI work?")
# Returns: "question"
intent = brain.detect_user_intent("Set a reminder for 3pm")
# Returns: "command"
intent = brain.detect_user_intent("I had a great day today")
# Returns: "casual"
import sys
sys.path.insert(0, "ClawBrain")
from clawbrain import Brain
class AssistantBot:
def __init__(self):
self.brain = Brain()
def handle_message(self, message, chat_id):
# Get context
context = self.brain.get_full_context(
session_key=f"telegram_{chat_id}",
user_id=str(chat_id),
agent_id="assistant",
message=message
)
# Generate response using context
response = self.generate_response(context)
# Learn from interaction
self.brain.learn_user_preference(
user_id=str(chat_id),
pref_type="interest",
value="AI"
)
return response
def generate_response(self, context):
# Use user preferences
name = context["user_profile"].name or "there"
mood = context["mood"]["mood"]
# Personalized response
if mood == "frustrated":
return f"Hey {name}, I'm here to help. Let me assist you."
else:
return f"Hi {name}! How can I help you today?"
def shutdown(self):
self.brain.close()
No configuration needed. Data stored in local SQLite database.
brain = Brain({"storage_backend": "sqlite"})
Best for: Development, testing, single-user deployments
Requires PostgreSQL and Redis servers.
brain = Brain() # Auto-detects
Requirements:
psycopg2-binary, redispip install psycopg2-binary redis
Best for: Production, multi-user, high-concurrency
clawbrain.py - Main Brain class with all featuresinit.py - Module exportsSKILL.md - This documentationskill.json - ClawdHub metadataREADME.md - Quick start guide# Ensure ClawBrain folder is in your path
sys.path.insert(0, "ClawBrain")
# Check environment variables
echo $POSTGRES_HOST
echo $POSTGRES_PORT
# Verify PostgreSQL is running
pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT
# Check Redis is running
redis-cli ping
If PostgreSQL/Redis are unavailable, Claw Brain automatically falls back to SQLite:
brain = Brain({"storage_backend": "sqlite"})
AI Usage Analysis
Analysis is being generated⦠refresh in a few seconds.
Captures learnings, errors, and corrections to enable continuous improvement. Use when: (1) A command or operation fails unexpectedly, (2) User corrects Clau...
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
Search and analyze your own session logs (older/parent conversations) using jq.
Typed knowledge graph for structured agent memory and composable skills. Use when creating/querying entities (Person, Project, Task, Event, Document), linking related objects, enforcing constraints, planning multi-step actions as graph transformations, or when skills need to share state. Trigger on "remember", "what do I know about", "link X to Y", "show dependencies", entity CRUD, or cross-skill data access.
Ultimate AI agent memory system for Cursor, Claude, ChatGPT & Copilot. WAL protocol + vector search + git-notes + cloud backup. Never lose context again. Vibe-coding ready.
Headless browser automation CLI optimized for AI agents with accessibility tree snapshots and ref-based element selection