Docs/Advanced/Drift Detection

Drift Detection

Compare agent sessions to detect behavioral drift — when an agent starts behaving differently for the same task.

import { Invariance } from '@invariance/sdk';

Overview

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.

Quick Example

Compare two sessions for drifttypescript
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);

API Reference

drift.catches
List automatically detected drift catches.
async catches(): Promise<DriftCatch[]>
ReturnsPromise<DriftCatch[]>
drift.compare
Compare two sessions for behavioral drift.
async compare(sessionA: string, sessionB: string): Promise<DriftComparison>
Parameters
sessionAstringFirst session ID
sessionBstringSecond session ID
ReturnsPromise<DriftComparison>

Use Cases

  • Detect behavioral changes after model or prompt updates
  • Compare agent behavior across environments (staging vs. production)
  • Identify regression patterns before they affect users
On this page
OverviewQuick ExampleAPI ReferenceUse CasesRelated Modules