Skip to main content
This document describes the system architecture of the Agent Alignment Protocol (AAP), including component relationships, data flow, and extension points.

Protocol stack

AAP operates as an alignment layer that extends existing agent protocols:
Key insight: AAP does not replace A2A or MCP — it extends them with alignment primitives.

Component architecture

Overview

Schemas module (aap.schemas)

The schemas module provides Pydantic models for the three core AAP components:

Alignment Card (alignment_card.py)

AP-Trace (ap_trace.py)

Value Coherence (value_coherence.py)

Verification engine (aap.verification)

The verification engine implements the three core operations:

verify_trace(trace, card) -> VerificationResult

Performs seven verification checks (SPEC Section 7.3), tracked in verification_metadata.checks_performed:
Returns VerificationResult:
  • verified: bool — True if no violations
  • recommended_action: "proceed" | "review" | "deny" — Derived from violations/warnings
  • violations: list[Violation] — Type, description, severity
  • warnings: list[Warning] — Near-boundary and low-similarity conditions
  • verification_metadata — Algorithm version, checks performed, duration

check_coherence(my_card, their_card) -> CoherenceResult

Computes value compatibility score (SPEC Section 6.4):
Returns CoherenceResult:
  • compatible: bool — Zero conflicts AND score >= 0.70 (MIN_COHERENCE_FOR_PROCEED)
  • score: float — Coherence score [0, 1]
  • value_alignment — Matched, unmatched, conflicts
  • proceed: bool — Mirrors compatible
  • proposed_resolution — If incompatible, suggests escalation

detect_drift(card, traces, thresholds) -> list[DriftAlert]

Analyzes trace sequence for behavioral drift (SPEC Section 8, v1.2.0 methodology):
Drift directions:
  • value_drift — Using undeclared values (>30% of recent)
  • autonomy_expansion — Escalation rate dropped by >50%
  • principal_misalignment — Declining confidence on principal_benefit
  • unknown — Pattern doesn’t match known categories

Feature extraction (features.py)

Structural feature extraction for drift detection (not TF-IDF — see calibration for why content tokens are excluded from drift scoring). TF-IDF weighting is used separately, for text-to-text SSM similarity:

Constants (constants.py)

Calibrated thresholds derived from corpus analysis (see calibration):

Data flow

Single trace verification

Multi-agent coherence check

Drift detection over time

Extension points

1. Custom values

Define domain-specific values in values.definitions:

2. Protocol extensions

Add protocol-specific data in extensions:

3. Custom escalation triggers

Define complex conditions in escalation_triggers:
Supported condition syntax (SPEC Section 4.6):
  • field == "value" — String equality
  • field > N — Numeric comparison (>, <, >=, <=, !=)
  • field_name — Boolean check (truthy)

4. Verification customization

Override default thresholds:

5. Integration hooks

For A2A integration, extend the Agent Card:
For MCP integration, add alignment to tool manifests:

Implementation notes

Python SDK

  • Location: src/aap/
  • Models: Pydantic v2 with strict validation
  • Type hints: Full coverage, py.typed marker
  • Dependencies: Only pydantic>=2.0

TypeScript SDK

  • Location: typescript/src/
  • Output formats: CJS, ESM, DTS
  • Types: Full TypeScript types, no any
  • Dependencies: None (zero runtime deps)

JSON schemas

  • Location: schemas/
  • Format: JSON Schema Draft 2020-12
  • Generated from: Pydantic models via model_json_schema()
Schemas can be used for:
  • Validation in any language (ajv, jsonschema, etc.)
  • Code generation (quicktype, json-schema-to-typescript)
  • Documentation (JSON Schema viewers)

Browser (Playground)

  • Live: mnemom.github.io/aap/playground
  • Runtime: Pyodide (Python in WASM)
  • API: window.AAP.verifyTrace(), window.AAP.checkCoherence(), window.AAP.detectDrift()
  • No server: All verification runs client-side

Security considerations

See security for the full threat model. Key points:
  1. AAP does not ensure alignment — It provides visibility, not guarantees
  2. AP-Traces are self-reported — Adversarial agents can lie
  3. Verification is point-in-time — Does not prevent future violations
  4. Thresholds are calibrated — But may not fit all domains
Defense in depth:
  • Use AAP alongside behavioral monitoring
  • Implement rate limiting and anomaly detection
  • Maintain human oversight for high-stakes decisions
  • Regularly audit AP-Trace storage for integrity

See also