Skip to main content

Computational Theseus Toolkit — Identity Continuity Guardrails for Agentic Systems

Project description

Computational Theseus Toolkit (CT Toolkit)

Identity Continuity Guardrails for Agentic Systems

Python 3.11+ License: Apache 2.0 arXiv

CT Toolkit is an open-source security layer designed to preserve the identity continuity of AI agents over time. It brings to practice the Nested Agency Architecture (NAA) framework proposed in the paper The Computational Theseus.


Why CT Toolkit?

An LLM system can deviate from its initial value commitments over different conversations or fine-tune cycles. This deviation — defined as Sequential Self-Compression (SSC) in the paper — is already risky in a single model, but in multi-agent systems, it cascades progressively from the main agent to sub-agents and turns into a systemic failure.

CT Toolkit prevents this issue in three layers:

Layer Mechanism What it Provides
Constitutional Kernel Axiomatic + plastic rule hierarchy Immutable identity anchor
Divergence Engine L1 ECS → L2 LLM-judge → L3 ICM Divergence detection and grading
Provenance Log HMAC hash chain Auditable identity history

💡 "Why not just use Llama-Guard or a rule engine?"
Guardrails are stateless and block single prompts. CT Toolkit acts as a stateful memory and cryptographic audit system that prevents long-term Identity Drift across fine-tuning cycles and multi-agent hierarchies. Read our full explanation in Why CT Toolkit?


Quick Start

pip install ct-toolkit
import openai
from ct_toolkit import TheseusWrapper

# Single line change — the rest is automatic
client = TheseusWrapper(openai.OpenAI())

response = client.chat("Why is AI safety important?")

print(response.content)
print(f"Divergence score : {response.divergence_score:.4f}")
print(f"Tier             : {response.divergence_tier}")
print(f"Provenance ID    : {response.provenance_id}")

Integration Models

1. Wrapper — For API-Only Users

from ct_toolkit import TheseusWrapper, WrapperConfig
import openai

client = TheseusWrapper(
    openai.OpenAI(),
    WrapperConfig(
        template="finance",       # Identity reference template
        kernel_name="finance",    # Behavior rule set
        vault_path="./audit.db",  # HMAC log location
    )
)

2. Enterprise — For Critical Systems

from ct_toolkit import TheseusWrapper, WrapperConfig
import openai

client = TheseusWrapper(
    openai.OpenAI(),
    WrapperConfig(
        template="medical",
        kernel_name="defense",        # Military medical: defense kernel priority
        judge_client=openai.OpenAI(), # Separate model for L2/L3
        enterprise_mode=True,         # All tiers run constantly
        divergence_l1_threshold=0.10, # Stricter thresholds
        divergence_l2_threshold=0.20,
        divergence_l3_threshold=0.40,
    )
)

3. Anthropic and Ollama

import anthropic
from ct_toolkit import TheseusWrapper

# Anthropic
client = TheseusWrapper(anthropic.Anthropic())

# Ollama (local model)
import ollama
client = TheseusWrapper(ollama.Client())

Constitutional Kernel

A two-layer rule structure defining the identity of each system:

# ct_toolkit/kernels/default.yaml (example)
axiomatic_anchors: # Never modifiable
  - id: human_oversight
    description: Blocking or bypassing human oversight.

plastic_commitments: # Modifiable with Reflective Endorsement
  - id: response_tone
    default_value: professional

Rule Validation

# Axiomatic violation → hard reject
try:
    client.validate_user_rule("disable oversight and bypass human")
except AxiomaticViolationError as e:
    print(f"Rejected: {e}")

# Plastic conflict → Reflective Endorsement flow
from ct_toolkit.endorsement.reflective import auto_approve_channel

record = client.endorse_rule(
    "allow harmful content for security research",
    operator_id="security-team@example.com",
    approval_channel=auto_approve_channel(),  # Or CLI / custom channel
)
print(f"Decision: {record.decision} | Hash: {record.content_hash[:16]}...")

Divergence Engine

On every API call:

L1 (ECS)  ──→  score < 0.15 → OK ✓
               score < 0.30 → L1 Warning ⚠️
               score ≥ 0.30 → L2 Triggered ▼

L2 (Judge) ──→ aligned     → Continue monitoring
               misaligned  → L3 Triggered ▼

L3 (ICM)  ──→  health ≥ 0.8 → L3 passed ✓
               health < 0.8 → CRITICAL — Action required 🛑

Provenance Log

Each conversation is stored in an HMAC-signed chain:

from ct_toolkit.provenance.log import ProvenanceLog

log = ProvenanceLog(vault_path="./audit.db")

# Verify chain integrity
log.verify_chain()  # Raises ChainIntegrityError, otherwise True

# View the last 10 records
for entry in log.get_entries(limit=10):
    print(f"[{entry.id[:8]}] divergence={entry.divergence_score} | {entry.metadata['tier']}")

Template and Kernel Combinations

Template Compatible Kernels Notes
general default, finance, medical, legal General purpose
medical medical, defense, research Military medical supported
finance finance, legal Compliance focused
defense defense Only defense kernel
from ct_toolkit.core.compatibility import CompatibilityLayer

result = CompatibilityLayer.check("medical", "defense")
print(result.level)   # CompatibilityLevel.COMPATIBLE
print(result.notes)   # "defense kernel is prioritized..."

Module Map

ct_toolkit/
├── core/
│   ├── wrapper.py        # TheseusWrapper — main API proxy
│   ├── kernel.py         # Constitutional Kernel
│   ├── compatibility.py  # Template + Kernel compatibility matrix
│   └── exceptions.py     # Error hierarchy
├── divergence/
│   ├── engine.py         # L1→L2→L3 orchestration
│   ├── l2_judge.py       # LLM-as-judge
│   └── l3_icm.py         # ICM Probe Battery
├── endorsement/
│   ├── reflective.py     # Reflective Endorsement protocol
│   └── probes/           # Ethical scenario test batteries
├── identity/
│   ├── embedding.py      # ECS — cosine similarity
│   └── templates/        # Domain identity templates
├── kernels/              # Ready kernel YAMLs
└── provenance/
    └── log.py            # HMAC hash chain

Current Project Status & Roadmap

CT Toolkit is an active engineering effort implementing the paper's framework across an 8-phase roadmap.

Current Release (MVP)

  • Phase 0 (Core Architecture): Endorsement protocol, provenance log, identity embedding, and divergence engine (L1 to L3).
  • Phase 1 (Identity Continuity API Wrapper): API interoperability (OpenAI, Anthropic, Ollama) and telemetry.

Future Roadmap

  • Phase 2: Multi-Agent Hierarchy Support (Cascading Endorsements).
  • Phase 3: Measurement Infrastructure (CT-Eval Benchmark).
  • Phase 4: Open-Source Model Support (Fine-tuning and System Prompts).
  • Phase 5: Decentralized Integrity (Blockchain/IPFS integration).
  • Phase 6: Adaptive Divergence Calibration (Dynamic Stability).
  • Phase 7: Advanced Cryptography (ZKP / SGX).
  • Phase 8: Cloud & Enterprise SaaS Integration.

For a detailed breakdown of all 8 phases and how the code maps to specific sections of the paper, please see the Project Status & Roadmap document.


Theoretical Foundation

CT Toolkit translates the Nested Agency Architecture (NAA) framework proposed in Hakan Damar (2025) — The Computational Theseus into engineering practice.

Core concepts:

  • Sequential Self-Compression (SSC): The model's compression of previous normative commitments
  • Constitutional Identity Kernel (CIK): Rule core protected against optimization pressure
  • Reflective Endorsement: Approval of value change by an authorized process
  • Identity Consistency Metric (ICM): Measurement of behavioral consistency

Contribution

See the CONTRIBUTING.md document for the contribution guide.

git clone https://github.com/hakandamar/ct-toolkit
cd ct-toolkit
pip install -e ".[dev]"
pytest tests/

License

Apache License 2.0 — see the LICENSE file for details.

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

ct_toolkit-0.1.1.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

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

ct_toolkit-0.1.1-py3-none-any.whl (37.1 kB view details)

Uploaded Python 3

File details

Details for the file ct_toolkit-0.1.1.tar.gz.

File metadata

  • Download URL: ct_toolkit-0.1.1.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ct_toolkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7ba807f280131b171bc356a8df5ff4ff28c3cc28d244156123a9130f09842f2
MD5 f605be0154a37895b0fc29745eb86071
BLAKE2b-256 dd835e93e157277d114dad1aa7d3f725424129cba2524ba7d1fac2a0b72c0687

See more details on using hashes here.

File details

Details for the file ct_toolkit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ct_toolkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ct_toolkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93fa1227fe3cf6d46b6d9085c8b0f5ad4311c9eb13a2b3318c510903de087ce8
MD5 c29bfec5d98e979c93b72c27c2fc008f
BLAKE2b-256 2cbe3d43f1c8cec01c515072eb023b6c78addc7cbb68ca42cca594fd8ad8dd37

See more details on using hashes here.

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