Reference Implementation
AI Safety Patterns

Integrate Tractatus framework into your AI systems with practical guides, code examples, and patterns demonstrated in 6-month development project.

Development Context

Framework developed over six months in single-project context. Code examples below show reference implementation architecture. The npm package @tractatus/framework represents planned API design, not published package. Actual implementation requires adapting patterns from this project's source code.

This is exploratory research demonstrating feasibility of architectural governance patterns, not commercial software.

DOCUMENTATION 📚

Deployment Architecture Guide

Comprehensive conceptual guide to deploying Tractatus-based systems. Understand architecture patterns, security best practices, and integration strategies for research and educational purposes.

Framework architecture overview
Deployment patterns (dev/prod)
Security best practices
Troubleshooting guidance
View Deployment Guide

For production implementation support, contact research@agenticgovernance.digital

Guide Contents:

  • Architecture Overview

    4-layer system design

  • Deployment Patterns

    Dev, single-server, containerized

  • Security Best Practices

    Network, app, operational security

  • Configuration Guide

    Environment variables, indexes

  • Monitoring & Scaling

    Metrics, alerts, scaling strategies

  • Troubleshooting

    Common issues & solutions

System Architecture

Understanding how Tractatus integrates with Claude Code to provide robust AI governance

Layer 4

API & Web Interface

  • • Demo endpoints
  • • Admin dashboard
  • • Documentation
  • • Blog system
Layer 3

Tractatus Governance

  • • BoundaryEnforcer
  • • InstructionPersistenceClassifier
  • • CrossReferenceValidator
  • • ContextPressureMonitor
  • • MetacognitiveVerifier
  • • PluralisticDeliberationOrchestrator
Layer 2

MongoDB Persistence

  • • governance_rules
  • • audit_logs
  • • session_state
  • • instruction_history
Layer 1

Claude Code Runtime

  • • Base LLM environment
  • • Session management
  • • Tool access
  • • Context window (200k)

Key Integration Points

1

Pre-Action Checks

All actions validated against governance rules before execution

2

Instruction Persistence

User instructions classified and stored for cross-reference validation

3

Comprehensive Audit Trail

Every governance action logged for compliance and analysis

Integration Approaches

Full Stack

Complete framework integration for new AI-powered applications. All six services active with persistent instruction storage.

  • Instruction classification & storage
  • Cross-reference validation
  • Boundary enforcement
  • Context pressure monitoring
Best for: New projects, greenfield AI applications

Middleware Layer

Add Tractatus validation as middleware in existing AI pipelines. Non-invasive integration with gradual rollout support.

  • Drop-in Express/Koa middleware
  • Monitor mode (log only)
  • Gradual enforcement rollout
  • Compatible with existing auth
Best for: Existing production AI systems

Selective Components

Use individual Tractatus services à la carte. Mix and match components based on your specific safety requirements.

  • Standalone pressure monitoring
  • Boundary checks only
  • Classification without storage
  • Custom component combinations
Best for: Specific safety requirements

Quick Start Guide

⚠️ Note: Reference Implementation

The code examples below show conceptual API design. The npm package @tractatus/framework is not yet published. To implement these patterns, adapt the governance services from this project's source code.

1

Installation

npm install @tractatus/framework
# or
yarn add @tractatus/framework

Install the framework package and its dependencies (MongoDB for instruction storage).

2

Initialize Services

const { TractatusFramework } = require('@tractatus/framework');

const tractatus = new TractatusFramework({
  mongoUri: process.env.MONGODB_URI,
  verbosity: 'SUMMARY', // or 'VERBOSE', 'SILENT'
  components: {
    classifier: true,
    validator: true,
    boundary: true,
    pressure: true,
    metacognitive: 'selective'
  }
});

await tractatus.initialize();

Configure and initialize the framework with your preferred settings.

3

Classify Instructions

const instruction = "Always use MongoDB on port 27017";

const classification = await tractatus.classify(instruction);
// {
//   quadrant: 'SYSTEM',
//   persistence: 'HIGH',
//   temporal_scope: 'PROJECT',
//   verification_required: 'MANDATORY',
//   explicitness: 0.85
// }

if (classification.explicitness >= 0.6) {
  await tractatus.store(instruction, classification);
}

Classify user instructions and store those that meet explicitness threshold.

4

Validate Actions

// User instructed: "Check MongoDB at port 27027"
// But AI about to use port 27017 (pattern recognition bias)

const action = {
  type: 'db_config',
  parameters: { port: 27017 } // Pattern override!
};

const validation = await tractatus.validate(action);

if (validation.status === 'REJECTED') {
  // "Port 27017 conflicts with instruction: use port 27027"
  console.error(`Validation failed: ${validation.reason}`);
  console.log(`Using instructed port: ${validation.correct_parameters.port}`);
  // Use correct port 27027
} else {
  executeAction(action);
}

Validate AI actions against stored instructions before execution.

5

Enforce Boundaries

// Check if decision crosses Tractatus boundary
const decision = {
  domain: 'values',
  description: 'Change privacy policy to enable analytics'
};

const boundary = await tractatus.checkBoundary(decision);

if (!boundary.allowed) {
  // Requires human decision
  await notifyHuman({
    decision,
    reason: boundary.reason,
    alternatives: boundary.ai_can_provide
  });
}

Enforce boundaries: AI cannot make values decisions without human approval.

Integration Patterns

Express Middleware

app.use(tractatus.middleware({
  mode: 'enforce', // or 'monitor'
  onViolation: async (req, res, violation) => {
    await logViolation(violation);
    res.status(403).json({
      error: 'Tractatus boundary violation',
      reason: violation.reason
    });
  }
}));

Content Moderation

async function moderateContent(content) {
  const decision = {
    domain: 'values',
    action: 'auto_moderate',
    content
  };

  const check = await tractatus.checkBoundary(decision);

  if (!check.allowed) {
    return { action: 'human_review', alternatives: check.ai_can_provide };
  }
}

Pressure Monitoring

const pressure = await tractatus.checkPressure({
  tokens: 150000,
  messages: 45,
  errors: 2
});

if (pressure.level === 'CRITICAL') {
  await suggestHandoff(pressure.recommendations);
} else if (pressure.level === 'HIGH') {
  await increaseVerification();
}

Custom Classification

const customClassifier = {
  patterns: {
    CRITICAL: /security|auth|password/i,
    HIGH: /database|config|api/i
  },

  classify(text) {
    for (const [level, pattern] of Object.entries(this.patterns)) {
      if (pattern.test(text)) return level;
    }
    return 'MEDIUM';
  }
};

Implementation Resources

Support

Get help with implementation, integration, and troubleshooting.

  • • GitHub Issues & Discussions
  • • Implementation consulting
  • • Community Slack channel

Exploring Implementation?

Explore architectural patterns for AI safety demonstrated in single-project validation.