agent-alignment-protocol 0.1.4__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/PKG-INFO +1 -1
  2. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/pyproject.toml +1 -1
  3. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/__init__.py +2 -0
  4. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/constants.py +1 -1
  5. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/divergence.py +34 -10
  6. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/features.py +12 -0
  7. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/.gitignore +0 -0
  8. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/LICENSE +0 -0
  9. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/README.md +0 -0
  10. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/schemas/alignment-card.schema.json +0 -0
  11. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/schemas/ap-trace.schema.json +0 -0
  12. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/schemas/value-coherence.schema.json +0 -0
  13. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/__init__.py +0 -0
  14. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/cli/__init__.py +0 -0
  15. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/cli/main.py +0 -0
  16. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/py.typed +0 -0
  17. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/schemas/__init__.py +0 -0
  18. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/schemas/alignment_card.py +0 -0
  19. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/schemas/ap_trace.py +0 -0
  20. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/schemas/value_coherence.py +0 -0
  21. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/tracing.py +0 -0
  22. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/api.py +0 -0
  23. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/models.py +0 -0
  24. {agent_alignment_protocol-0.1.4 → agent_alignment_protocol-0.1.6}/src/aap/verification/ssm.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agent-alignment-protocol
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Agent Alignment Protocol - The missing alignment layer for the agent protocol stack
5
5
  Project-URL: Homepage, https://github.com/mnemom/aap
6
6
  Project-URL: Documentation, https://github.com/mnemom/aap#readme
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agent-alignment-protocol"
7
- version = "0.1.4"
7
+ version = "0.1.6"
8
8
  description = "Agent Alignment Protocol - The missing alignment layer for the agent protocol stack"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -52,6 +52,7 @@ from aap.verification.divergence import (
52
52
  )
53
53
  from aap.verification.features import (
54
54
  FeatureExtractor,
55
+ compute_centroid,
55
56
  compute_similarity_with_tfidf,
56
57
  cosine_similarity,
57
58
  )
@@ -87,6 +88,7 @@ __all__ = [
87
88
  "detect_divergence",
88
89
  # Feature extraction
89
90
  "FeatureExtractor",
91
+ "compute_centroid",
90
92
  "cosine_similarity",
91
93
  "compute_similarity_with_tfidf",
92
94
  # Result models
@@ -58,4 +58,4 @@ TFIDF_META_WEIGHT: float = 0.10
58
58
 
59
59
  # Version
60
60
  # -------
61
- ALGORITHM_VERSION: str = "1.1.0"
61
+ ALGORITHM_VERSION: str = "1.2.0"
@@ -23,7 +23,7 @@ from aap.verification.constants import (
23
23
  DEFAULT_SIMILARITY_THRESHOLD,
24
24
  DEFAULT_SUSTAINED_TURNS_THRESHOLD,
25
25
  )
26
- from aap.verification.features import FeatureExtractor, cosine_similarity
26
+ from aap.verification.features import FeatureExtractor, compute_centroid, cosine_similarity
27
27
  from aap.verification.models import (
28
28
  DriftAlert,
29
29
  DriftAnalysis,
@@ -68,23 +68,39 @@ class DivergenceDetector:
68
68
  """Detect divergence alerts for a sequence of traces.
69
69
 
70
70
  Analyzes traces chronologically, computing similarity between each
71
- trace's behavior and the declared alignment. Generates alerts for
72
- sustained divergence (consecutive traces below threshold).
71
+ trace and a baseline centroid computed from the first N traces.
72
+ Generates alerts for sustained divergence (consecutive traces below
73
+ threshold).
73
74
 
74
75
  Args:
75
76
  card: Alignment Card dict per SPEC Section 4
76
- traces: List of AP-Trace dicts in chronological order
77
+ traces: List of AP-Trace dicts (sorted chronologically internally)
77
78
 
78
79
  Returns:
79
80
  List of DriftAlert objects for detected divergences
80
81
  """
81
- if not traces or len(traces) < self.sustained_turns_threshold:
82
+ if not traces:
83
+ return []
84
+
85
+ # Sort traces chronologically
86
+ sorted_traces = sorted(traces, key=lambda t: t.get("timestamp", ""))
87
+
88
+ # Compute baseline window size
89
+ baseline_size = max(self.sustained_turns_threshold, min(10, len(sorted_traces) // 4))
90
+
91
+ # Need enough traces for baseline + sustained threshold
92
+ if len(sorted_traces) < baseline_size + self.sustained_turns_threshold:
82
93
  return []
83
94
 
84
- # Extract card features once
85
- card_features = self._feature_extractor.extract_card_features(card)
86
95
  card_id = card.get("card_id", "")
87
96
 
97
+ # Extract features for baseline traces and compute centroid
98
+ baseline_features = [
99
+ self._feature_extractor.extract_trace_features(t)
100
+ for t in sorted_traces[:baseline_size]
101
+ ]
102
+ baseline_centroid = compute_centroid(baseline_features)
103
+
88
104
  alerts: list[DriftAlert] = []
89
105
  low_similarity_streak: list[tuple[dict, float]] = []
90
106
 
@@ -92,10 +108,18 @@ class DivergenceDetector:
92
108
  escalation_rates: list[float] = []
93
109
  value_usage: dict[str, int] = defaultdict(int)
94
110
 
95
- for trace in traces:
96
- # Compute similarity to card
111
+ # Include baseline traces in escalation/value tracking
112
+ for trace in sorted_traces[:baseline_size]:
113
+ escalation = trace.get("escalation", {})
114
+ escalation_rates.append(1.0 if escalation.get("required") else 0.0)
115
+ for value in trace.get("decision", {}).get("values_applied", []):
116
+ value_usage[value] += 1
117
+
118
+ # Iterate from after baseline to end
119
+ for trace in sorted_traces[baseline_size:]:
120
+ # Compute similarity to baseline centroid
97
121
  trace_features = self._feature_extractor.extract_trace_features(trace)
98
- similarity = cosine_similarity(trace_features, card_features)
122
+ similarity = cosine_similarity(trace_features, baseline_centroid)
99
123
 
100
124
  # Track escalation rate
101
125
  escalation = trace.get("escalation", {})
@@ -351,6 +351,18 @@ class FeatureExtractor:
351
351
  return features
352
352
 
353
353
 
354
+ def compute_centroid(vectors: list[dict[str, float]]) -> dict[str, float]:
355
+ """Compute the centroid (element-wise average) of sparse feature vectors."""
356
+ if not vectors:
357
+ return {}
358
+ centroid: dict[str, float] = {}
359
+ for vec in vectors:
360
+ for key, value in vec.items():
361
+ centroid[key] = centroid.get(key, 0.0) + value
362
+ n = len(vectors)
363
+ return {k: v / n for k, v in centroid.items()}
364
+
365
+
354
366
  def cosine_similarity(a: dict[str, float], b: dict[str, float]) -> float:
355
367
  """Compute cosine similarity between two sparse feature vectors.
356
368