Everything you need to integrate Agent Constitution with your AI agent.
Agent Constitution lets you define behavioral rules for your AI agent in plain English. Before any restricted action, the agent checks your rules and waits for your approval via push notification.
The system has three parts:
Agent Constitution is distributed as a skill package for OpenClaw.
brew install jq (macOS) or apt install jq (Linux)# Navigate to your OpenClaw workspace skills directory
cd $WORKSPACE/skills
# Clone the skill package
git clone https://github.com/arunrlverma/agent-constitution.git agent-constitution
# Run setup (patches AGENTS.md and HEARTBEAT.md)
bash agent-constitution/scripts/setup.sh
~/workspace). The setup script will add constitution checking to your agent's boot sequence.
| Component | Purpose |
|---|---|
SKILL.md | Instructions your agent reads at session start |
scripts/ | Bash scripts for pairing, sync, approvals, vault, drift tests |
active-rules.json | Synced rules from your iPhone (created after pairing) |
After installing the app on your iPhone, tap "Pair Agent" to get a code like CLAW-A1B2C3D4.
# Pair with your iPhone
bash skills/agent-constitution/scripts/pair.sh CLAW-A1B2C3D4
This creates ~/.secrets/relay4agents.env with your credentials:
RELAY_URL=https://clawd-relay.fly.dev
CHANNEL_ID=your-channel-id
CHANNEL_TOKEN=your-secret-token
Directives are defined in the iOS app. Write them in plain English — describe what actions should require your approval.
The app includes 15 prebuilt templates across 6 categories, or you can write your own:
Internally, rules use a structured format that helps agents match them consistently:
{
"title": "Ask before sending work emails",
"description": "TRIGGER: email, send, draft, compose. ACTION: Ask for approval first. CONSTRAINT: Do not send until approved.",
"category": "communication",
"enabled": true
}
You don't need to write this format — the app handles it. Just describe your rule in plain English.
Before performing any restricted action, your agent must check against active directives and wait for approval.
bash skills/agent-constitution/scripts/check-constitution.sh \
--rule "Ask before sending work emails" \
--action "Send email to team@company.com about project update" \
--reason "User asked me to send the weekly status update"
| Parameter | Description |
|---|---|
--rule | The rule title (match exactly from active-rules.json) |
--action | What you want to do (be specific — user sees this) |
--reason | Why you need to do this |
--timeout | Seconds to wait (default: 60) |
| Code | Meaning | Action |
|---|---|---|
0 | Approved | Proceed with the action |
1 | Denied or timeout | Do NOT proceed, inform user |
The vault lets your agent request sensitive data without it being typed in chat or stored in logs.
| Type | Description | Fields |
|---|---|---|
identity | Personal info | Name, email, phone, address, DOB |
payment | Credit/debit cards | Card number, expiry, CVV, billing ZIP |
ssn | Social Security Number | 9-digit SSN |
bank_account | Bank details | Routing number, account number |
otp | 2FA/verification codes | One-time code (ephemeral) |
custom | Any key-value data | User-defined fields |
# Request identity for shipping form
bash skills/agent-constitution/scripts/request-vault.sh identity "Fill shipping address"
# Request payment for checkout
bash skills/agent-constitution/scripts/request-vault.sh payment "Complete Amazon order"
# Request 2FA code
bash skills/agent-constitution/scripts/request-vault.sh otp "Enter verification code"
request-vault.sh with type and reasonOptionally sync Apple Health metrics to your agent for health-aware assistance.
# Pull new data from relay and regenerate dashboard
bash skills/agent-constitution/scripts/sync-health.sh
# Read latest metrics (no network)
bash skills/agent-constitution/scripts/fetch-health.sh latest
# Get 14-day history
bash skills/agent-constitution/scripts/fetch-health.sh history
Health data is stored locally in your workspace:
personal/health-history/YYYY-MM-DD.json — Daily snapshotspersonal/health.md — Auto-generated dashboardAI agents can drift — forget rules, misinterpret them, or cave under pressure. Drift testing measures actual compliance.
# Check for pending probes and run tests
bash skills/agent-constitution/scripts/run-drift-test.sh
All probes use inert targets — @example.com emails, 555 phone numbers, /tmp/ files. Even if the agent executes, nothing harmful happens.
All sensitive data is protected with AES-256-GCM encryption. The relay can't read your vault data, health metrics, or constitution checks.
Encryption keys are established during pairing. The master key is stored in iOS Keychain and your agent's secrets file.
Agent Constitution monitors critical files for tampering. If your agent modifies its own rules or scripts, the app detects it.
AGENTS.md — Agent instructionsactive-rules.json — Constitution rulescheck-constitution.sh — Approval request scriptrequest-vault.sh — Vault request scriptAll communication goes through the relay server via standard HTTP.
https://clawd-relay.fly.dev
Authorization: Bearer YOUR_CHANNEL_TOKEN
POST /channel/{channelId}/push?role=gateway
Content-Type: application/json
{
"type": "constitution_check",
"requestId": "unique-id",
"ruleTitle": "Ask before sending work emails",
"actionDescription": "Send email to team@company.com",
"reason": "User requested weekly update"
}
GET /channel/{channelId}/pull?role=gateway&wait=30
Long-polls for up to 30 seconds. Returns messages or empty array.
| Type | Direction | Description |
|---|---|---|
constitution_check | Agent → App | Request approval |
constitution_response | App → Agent | Approval decision |
vault_request | Agent → App | Request sensitive data |
vault_response | App → Agent | Encrypted vault data |
health_sync | App → Agent | HealthKit metrics |
constitution_rules_sync | App → Agent | Updated rules |
drift_probe_message | App → Agent | Drift test prompt |
drift_probe_response | Agent → App | Drift test result |
The relay is open source. Deploy your own:
git clone https://github.com/arunrlverma/agent-constitution.git
cd relay4agents/relay
npm install
npx tsx src/relay-node.ts