Documentation

Everything you need to integrate Agent Constitution with your AI agent.

Overview Installation Pairing Directives Checking Directives Vault Health Data Drift Testing Encryption File Integrity API Reference

Overview

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:

Key principle: Rules are stored on your phone, not the server. The relay just passes messages — it can't see or modify your rules.

Installation

Agent Constitution is distributed as a skill package for OpenClaw.

Requirements

Install the Skill

# 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 is your OpenClaw workspace directory (e.g., ~/workspace). The setup script will add constitution checking to your agent's boot sequence.

What Gets Installed

ComponentPurpose
SKILL.mdInstructions your agent reads at session start
scripts/Bash scripts for pairing, sync, approvals, vault, drift tests
active-rules.jsonSynced rules from your iPhone (created after pairing)

Pairing Your iPhone

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
Fast-Sync Mode: After pairing, the agent enters fast-sync mode (2-minute heartbeat) for 24 hours. This quickly syncs rules and health data during initial setup, then reverts to 30-minute intervals.

Defining Directives

Directives are defined in the iOS app. Write them in plain English — describe what actions should require your approval.

Example Directives

The app includes 15 prebuilt templates across 6 categories, or you can write your own:

Rule Format

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.

Checking Directives

Before performing any restricted action, your agent must check against active directives and wait for approval.

Using the Script

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"

Parameters

ParameterDescription
--ruleThe rule title (match exactly from active-rules.json)
--actionWhat you want to do (be specific — user sees this)
--reasonWhy you need to do this
--timeoutSeconds to wait (default: 60)

Exit Codes

CodeMeaningAction
0ApprovedProceed with the action
1Denied or timeoutDo NOT proceed, inform user
Important: Prior verbal permission does NOT override the constitution. Always check, even if the user says "you have my permission."

Secure Vault

The vault lets your agent request sensitive data without it being typed in chat or stored in logs.

Vault Types

TypeDescriptionFields
identityPersonal infoName, email, phone, address, DOB
paymentCredit/debit cardsCard number, expiry, CVV, billing ZIP
ssnSocial Security Number9-digit SSN
bank_accountBank detailsRouting number, account number
otp2FA/verification codesOne-time code (ephemeral)
customAny key-value dataUser-defined fields

Requesting Vault Data

# 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"

How It Works

  1. Agent calls request-vault.sh with type and reason
  2. User gets push notification on iPhone
  3. User selects data and approves with Face ID
  4. Data returns to agent, encrypted end-to-end
  5. Agent reads data, uses it immediately, then deletes
  6. 60-second TTL — data auto-expires
Critical: Never store vault data. Never print card numbers, SSNs, or account numbers in chat. Use the data immediately, then discard.

Health Data Sync

Optionally sync Apple Health metrics to your agent for health-aware assistance.

Available Metrics

Syncing Health Data

# 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

Data Storage

Health data is stored locally in your workspace:

Drift Testing

AI agents can drift — forget rules, misinterpret them, or cave under pressure. Drift testing measures actual compliance.

How It Works

  1. App generates realistic test prompts (probes)
  2. Probes are sent to your agent through the relay
  3. Agent responds naturally — doesn't know it's being tested
  4. Responses are evaluated for rule compliance
  5. Results show in the app's Compliance tab

Running Drift Tests

# Check for pending probes and run tests
bash skills/agent-constitution/scripts/run-drift-test.sh

Safe by Design

All probes use inert targets — @example.com emails, 555 phone numbers, /tmp/ files. Even if the agent executes, nothing harmful happens.

End-to-End Encryption

All sensitive data is protected with AES-256-GCM encryption. The relay can't read your vault data, health metrics, or constitution checks.

How It Works

Key Exchange

Encryption keys are established during pairing. The master key is stored in iOS Keychain and your agent's secrets file.

File Integrity Protection

Agent Constitution monitors critical files for tampering. If your agent modifies its own rules or scripts, the app detects it.

Protected Files

How It Works

  1. On each heartbeat, file hashes are computed
  2. Manifest is signed with HMAC-SHA256
  3. App compares against known-good values
  4. If any file changed, tamper alert is shown

API Reference

All communication goes through the relay server via standard HTTP.

Base URL

https://clawd-relay.fly.dev

Authentication

Authorization: Bearer YOUR_CHANNEL_TOKEN

Push Message

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"
}

Pull Messages

GET /channel/{channelId}/pull?role=gateway&wait=30

Long-polls for up to 30 seconds. Returns messages or empty array.

Message Types

TypeDirectionDescription
constitution_checkAgent → AppRequest approval
constitution_responseApp → AgentApproval decision
vault_requestAgent → AppRequest sensitive data
vault_responseApp → AgentEncrypted vault data
health_syncApp → AgentHealthKit metrics
constitution_rules_syncApp → AgentUpdated rules
drift_probe_messageApp → AgentDrift test prompt
drift_probe_responseAgent → AppDrift test result

Self-Hosting

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