Compare agent sessions to detect behavioral drift — when an agent starts behaving differently for the same task.
Drift detection compares two agent sessions performing similar tasks and identifies where behavior diverged. It produces a similarity score and pinpoints the exact step where drift occurred.
Use drift detection to catch when model updates, prompt changes, or environment shifts cause agents to behave differently than expected.
const inv = Invariance.init({ apiKey: process.env.INVARIANCE_API_KEY! });
// List detected drift catches
const catches = await inv.drift.catches();
// Compare two specific sessions
const comparison = await inv.drift.compare('session-a-id', 'session-b-id');
console.log('Similarity:', comparison.similarity_score);
console.log('Divergence at step:', comparison.divergence_point);