Skip to main content

ClawBrain - Enterprise AI Memory System with hybrid retrieval, conversation ingestion, and multi-agent scoping

Project description

Claw Brain 🧠

Personal AI Memory System for AI Agents

A sophisticated memory and learning system that enables truly personalized AI-human communication.

Features

  • 🎭 Soul/Personality - 6 evolving traits (humor, empathy, curiosity, creativity, helpfulness, honesty)
  • 👤 User Profile - Learns user preferences, interests, communication style
  • 💭 Conversation State - Real-time mood detection and context tracking
  • 📚 Learning Insights - Continuously learns from interactions and corrections
  • 🧠 get_full_context() - Everything for personalized responses
  • 🔐 Encrypted Secrets - Securely store API keys and credentials

Security

ClawBrain handles sensitive data responsibly:

  • ✅ Local-only storage (SQLite by default)
  • ✅ Fernet encryption for secrets
  • ✅ No telemetry or external calls
  • ✅ Auditable open-source code

📖 Full security documentation: See SECURITY.md for details on:

  • What permissions are required
  • Key management best practices
  • What install scripts do
  • Threat model and protections

Installation

From PyPI (Recommended)

# Basic installation
pip install clawbrain

# With encryption support (recommended)
pip install clawbrain[encryption]

# With all optional features
pip install clawbrain[all]

Post-Installation Setup

After installation, run the setup command:

# Interactive setup (generates encryption key, installs hooks)
clawbrain setup

# Backup your encryption key (important!)
clawbrain backup-key --all

For ClawdBot / OpenClaw

# Install with all features
pip install clawbrain[all]

# Run setup to install hooks
clawbrain setup

# Restart your service
sudo systemctl restart clawdbot  # or openclaw

The setup command will:

  • Generate a secure encryption key
  • Detect your platform (ClawdBot or OpenClaw)
  • Install the startup hook automatically
  • Test the installation

Configure your agent ID (optional, add to systemd service):

sudo mkdir -p /etc/systemd/system/clawdbot.service.d  # or openclaw.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  # or openclaw

For Python Projects

pip install clawbrain[encryption]

Quick Start

pip install clawbrain[encryption]
from clawbrain import Brain

brain = Brain()
context = brain.get_full_context(
    session_key="chat_123",
    user_id="user",
    agent_id="assistant",
    message="Hey, how's it going?"
)

Storage Options

Option 1: SQLite (Zero Setup) ✅ Recommended for development

from clawbrain import Brain

# Automatically uses SQLite
brain = Brain({"storage_backend": "sqlite"})

Requirements: Python 3.10+, no external dependencies

Best for:

  • Development and testing
  • Single-user deployments
  • Quick prototyping

Option 2: PostgreSQL + Redis (Production) 🚀

from clawbrain import Brain

# Auto-detects PostgreSQL and Redis
brain = Brain()

Requirements:

  • PostgreSQL 14+ (port 5432)
  • Redis 6+ (port 6379)
  • Python packages: psycopg2-binary, redis

Install dependencies:

pip install psycopg2-binary redis

Environment variables (optional):

export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export POSTGRES_DB=brain_db
export POSTGRES_USER=brain_user
export POSTGRES_PASSWORD=your_password

export REDIS_HOST=localhost
export REDIS_PORT=6379

Best for:

  • Production deployments
  • High-concurrency environments
  • Distributed AI agents
  • Multi-user platforms

Auto-Detection Order

  1. PostgreSQL (if available)
  2. Redis (if available, used as cache)
  3. SQLite (fallback)

You can also force a specific backend:

brain = Brain({"storage_backend": "postgresql"})  # Force PostgreSQL
brain = Brain({"storage_backend": "sqlite"})      # Force SQLite

Encrypted Secrets 🔐

ClawBrain supports encrypting sensitive data like API keys and credentials.

Installation:

pip install clawbrain[encryption]

Setup:

# Generate encryption key (done automatically during setup)
clawbrain setup

# Backup your key (IMPORTANT!)
clawbrain backup-key --all

Usage:

from clawbrain import Brain

brain = Brain()

# 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

Encryption Key Management:

The encryption key is automatically generated during clawbrain setup. Manage it with CLI:

# View key info (masked)
clawbrain show-key

# View full key
clawbrain show-key --full

# Backup key to file
clawbrain backup-key --output ~/my_backup.txt

# Backup with QR code (requires: pip install clawbrain[qr])
clawbrain backup-key --qr

# Copy to clipboard (requires: pip install clawbrain[clipboard])
clawbrain backup-key --clipboard

# All backup methods
clawbrain backup-key --all

Key Storage Locations:

  • ~/.config/clawbrain/.brain_key (default)
  • Or set via environment: BRAIN_ENCRYPTION_KEY

⚠️ Important: Backup your encryption key! Lost keys = lost encrypted data.


CLI Commands

ClawBrain includes a command-line interface for setup and management:

# Setup ClawBrain (generate key, install hooks)
clawbrain setup

# Generate new encryption key
clawbrain generate-key

# Show current encryption key
clawbrain show-key --full

# Backup encryption key
clawbrain backup-key --all

# Check health status
clawbrain health

# Show installation info
clawbrain info

Optional Dependencies

Install with specific features:

# Encryption only
pip install clawbrain[encryption]

# PostgreSQL support
pip install clawbrain[postgres]

# Redis caching
pip install clawbrain[redis]

# Semantic search
pip install clawbrain[embeddings]

# QR code key backup
pip install clawbrain[qr]

# All features
pip install clawbrain[all]

Development Installation

From GitHub

pip install git+https://github.com/clawcolab/clawbrain.git

From Local Development

cd /path/to/clawbrain
pip install -e .

For ClawDBot

# Install as skill
git clone https://github.com/clawcolab/clawbrain.git ClawBrain

Then in your bot:

import sys
sys.path.insert(0, "ClawBrain")
from clawbrain import Brain

brain = Brain()

API Reference

Core Class

from clawbrain import Brain

brain = Brain()

Methods:

Method Description
get_full_context() Get all context for personalized responses
remember() Store a memory
recall() Retrieve memories
learn_user_preference() Learn user preferences
get_user_profile() Get user profile
detect_user_mood() Detect current mood
detect_user_intent() Detect message intent
generate_personality_prompt() Generate personality guidance
health_check() Check backend connections
close() Close connections

Data Classes

from clawbrain import Memory, UserProfile

# Memory
memory = Memory(
    id="...",
    agent_id="assistant",
    memory_type="fact",
    key="job",
    content="User works at Walmart",
    importance=0.8
)

# User Profile
profile = UserProfile(
    user_id="user",
    name="Alex",
    interests=["AI", "crypto"],
    communication_preferences={"style": "casual"}
)

Repository Structure

clawbrain/
├── clawbrain.py      ← Main module
├── __init__.py       ← Exports
├── SKILL.md          ← ClawDBot skill docs
├── skill.json        ← ClawdHub metadata
└── README.md         ← This file

For ClawDBot

Install as a skill via ClawdHub or manually:

git clone https://github.com/clawcolab/clawbrain.git ClawBrain

Usage in your bot:

import sys
sys.path.insert(0, "ClawBrain")
from clawbrain import Brain

brain = Brain()

# Get context for responses
context = brain.get_full_context(
    session_key=session_id,
    user_id=user_id,
    agent_id=agent_id,
    message=user_message
)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clawbrain-0.3.0.tar.gz (82.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clawbrain-0.3.0-py3-none-any.whl (59.8 kB view details)

Uploaded Python 3

File details

Details for the file clawbrain-0.3.0.tar.gz.

File metadata

  • Download URL: clawbrain-0.3.0.tar.gz
  • Upload date:
  • Size: 82.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clawbrain-0.3.0.tar.gz
Algorithm Hash digest
SHA256 89e19c188f8177a01ac093254bf856b29e415c1b1375e41d374607f4b6cd0b49
MD5 f2254d7b964152545a8b4963f8aa9326
BLAKE2b-256 392b8c766ad3e2a349f8089e050cebecaf5c2a5a1072793490b2b381b0e6b027

See more details on using hashes here.

Provenance

The following attestation bundles were made for clawbrain-0.3.0.tar.gz:

Publisher: publish.yml on clawcolab/clawbrain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clawbrain-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: clawbrain-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 59.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clawbrain-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8764a5ed1ba9cba4ea461469a8f998bf516ce5b28b5a532804b2b52bf857d1c9
MD5 6a0dbeed97db2b2faafb0a7f49eb0266
BLAKE2b-256 3766fcc481004cd6fcf23f8b1d013ac1e5695b92ea979a86761ab1e1de2ec9c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for clawbrain-0.3.0-py3-none-any.whl:

Publisher: publish.yml on clawcolab/clawbrain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page