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 six verification checks (SPEC Section 7.3):
Returns VerificationResult:
  • verified: bool — True if no violations
  • violations: list[Violation] — Type, description, severity
  • warnings: list[Warning] — Near-boundary 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 — No conflicts AND score >= 0.5
  • score: float — Coherence score [0, 1]
  • value_alignment — Matched, unmatched, conflicts
  • proceed: bool — Safe to collaborate
  • proposed_resolution — If incompatible, suggests escalation

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

Analyzes trace sequence for behavioral drift (SPEC Section 8):
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)

TF-IDF-based feature extraction for drift detection:

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)

  • Location: docs/playground/
  • Runtime: Pyodide (Python in WASM)
  • API: window.AAP.verifyTrace(), etc.
  • 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