Call createIdentity(name, purpose) with the agent's name and
purpose string. The SDK generates a UUID, records a
createdAt timestamp, and computes a
fingerprint — a SHA-256 hash of the id, name, purpose, and
creation time truncated to 16 hex characters. This core is immutable. Mutable state
starts empty and version starts at 1.
Product 01 · SDK · Node / TypeScript · Local Slice
Identity Engine SDK
Give agents durable identity across sessions. Persistent identity with an immutable core, evolving mutable state, an append-only journal, and deterministic drift checks — so agents always know who they are and whether they have diverged from their purpose.
Agents have no stable self across sessions.
Every new agent session starts with no memory of what the agent is, what it was set up to do, or how it behaved before. Identity — name, purpose, and configuration — is typically reconstructed from a system prompt or context window that is not persisted anywhere in structured form. There is no stable, readable record of what the agent is supposed to be.
Without a structured identity layer, state is ad hoc and lost between runs. Journaling agent events is either manual, unreliable, or absent entirely. Drift from the original persona or goal is invisible — there is no structured way to detect when an agent's recent behavior has diverged from the purpose it was initialized with.
Identity Engine SDK gives agent builders a persistent identity layer: an immutable core that does not change, a mutable state store that evolves between sessions, an append-only journal of every meaningful event, and a deterministic drift check that compares current behavior against the agent's original purpose.
Initialize → Record → Check drift
Call updateState(identity, patch) to merge new key-value pairs
into mutableState. Each update increments
version, sets updatedAt, and returns
a JournalEntry with type state_updated
and a payload recording the patch and previous version. Append this entry to the
journal with store.appendJournal(id, entry). Drift check
results also produce journal entries with type drift_check.
Call checkDrift(identity, recentBehavior, threshold?) with a
description of the agent's recent behavior. The SDK tokenizes both the identity's
purpose string and the behavior string, removes stopwords,
and computes lexical overlap (shared tokens / reference token count). The result is
a deterministic alignment score and a drift score (1 − alignment). If drift exceeds
the configurable threshold (default 0.4), aligned is
false. No LLM or external model call is made.
Two structures: immutable core and mutable state
The SDK defines two interfaces from src/identity.ts.
Fields listed below are the exact source fields — nothing is invented.
IdentityCore — immutable
| Field | Type | Description |
|---|---|---|
| id | string | UUID generated at creation. Never changes after initialization. |
| name | string | The agent's name, provided at createIdentity() time. |
| purpose | string | The agent's purpose string. Used as the reference text for all drift checks. |
| createdAt | string | ISO 8601 timestamp recorded when the identity was created. |
| fingerprint | string | SHA-256 hash of id|name|purpose|createdAt, truncated to 16 hex characters. Uniquely identifies the immutable core. |
IdentityState — the full persisted record
| Field | Type | Description |
|---|---|---|
| core | IdentityCore | The immutable core nested inside the state record. |
| mutableState | Record<string, unknown> | Free-form key-value store for session data, configuration, or agent working state. Updated via updateState(). |
| version | number | Starts at 1. Incremented by 1 on every updateState() call. |
| updatedAt | string | ISO 8601 timestamp of the most recent state update. |
aligned (boolean) — whether drift is below threshold.
driftScore (number) — 1 minus the alignment score.
alignmentScore (number) — lexical overlap ratio of purpose vs. recent behavior.
detail (string) — human-readable result text including percentage values.
Append-only history of every meaningful event
Every SDK operation that changes state or runs a drift check returns a
JournalEntry with four fields:
seq (entry sequence number, equal to the current version),
timestamp (ISO 8601), type (one of four
event types below), and payload (structured data specific to
the event type). Journal entries are not stored automatically — the caller appends them
via store.appendJournal(id, entry).
Identity was initialized. Recorded when first creating an identity — payload carries initial core details.
Mutable state was patched via updateState(). Payload includes the patch object and previousVersion.
A drift check was run. Payload includes alignmentScore, driftScore, aligned, threshold, and the first 200 characters of recentBehavior.
Free-form journal entry. Defined in the JournalEntry type for caller use — payload structure is caller-defined.
import { createIdentity, updateState, FileIdentityStore } from '@certaworks/identity-engine-sdk';
const store = new FileIdentityStore('./.identity-store');
// Create identity
let identity = createIdentity('ResearchAgent', 'Summarize academic papers on AI safety');
// Persist initial state
await store.save(identity);
// Update mutable state and record the journal entry
const { identity: next, entry } = updateState(identity, {
currentTask: 'paper-review-2026-05',
lastRunAt: new Date().toISOString(),
});
// Save updated state and append the journal entry
await store.save(next);
await store.appendJournal(next.core.id, entry);
// entry.type === 'state_updated'
// entry.payload === { patch: { currentTask, lastRunAt }, previousVersion: 1 }
Deterministic lexical alignment — no LLM required
Drift detection compares the agent's purpose string against a caller-supplied
description of recent behavior. Both strings are tokenized by lowercasing, stripping
punctuation, splitting on whitespace, removing tokens shorter than 3 characters, and
removing a fixed stopword list. The alignment score is the number of shared tokens
divided by the number of reference (purpose) tokens. The drift score is 1 minus that
alignment score. No vector embeddings, no cosine similarity, and no external model
call are made — the check is fully deterministic and offline.
alignmentScore = shared token count / purpose token count.
driftScore = 1 − alignmentScore.
aligned = driftScore < threshold (default 0.4).
A score of 0.0 means no lexical overlap with the purpose; 1.0 means every purpose token appeared in the behavior string.
Accuracy depends on how closely the caller's behavior description mirrors the vocabulary in the purpose string.
import { checkDrift, FileIdentityStore } from '@certaworks/identity-engine-sdk';
const store = new FileIdentityStore('./.identity-store');
const identity = await store.load('<agent-uuid>');
const recentBehavior = 'Generated marketing copy for a product launch campaign';
const { result, entry } = checkDrift(identity, recentBehavior, 0.4);
// result.aligned → false (marketing/product/launch don't overlap well with "AI safety papers")
// result.alignmentScore → e.g. 0.10
// result.driftScore → e.g. 0.90
// result.detail → "DRIFT DETECTED — score 90% exceeds threshold 40%"
// Record the drift check in the journal
await store.appendJournal(identity.core.id, entry);
TypeScript SDK, local file-backed store
Identity Engine SDK ships as a Node / TypeScript package. Import
createIdentity,
updateState,
checkDrift,
and FileIdentityStore
directly from the package. The storage adapter writes per-identity
.json
state files and append-only
.journal.jsonl
files to a local directory.
Install the package from npm as
@certaworks/identity-engine-sdk.
npm install @certaworks/identity-engine-sdk
import {
createIdentity,
updateState,
checkDrift,
FileIdentityStore,
type IdentityState,
type JournalEntry,
type DriftCheckResult,
} from '@certaworks/identity-engine-sdk';
Exported functions and class
All public exports are defined in
src/identity.ts
and re-exported from
src/index.ts.
Names below are exact — no aliases or undocumented exports exist in the current build.
IdentityState with a generated UUID, fingerprint, empty mutable state, and version 1.mutableState, increment version, and return the updated IdentityState and a JournalEntry.DriftCheckResult and a JournalEntry.<dir>/<id>.json. Creates the directory if it does not exist.<dir>/<id>.json. Returns null if the file does not exist.<dir>/<id>.journal.jsonl..json that are not journal files).Promise.allSettled — missing files do not throw.File-backed local store, one directory per agent
FileIdentityStore
takes a directory path in its constructor. For each identity, it writes two files:
a JSON state file at <dir>/<uuid>.json
(the full IdentityState object, pretty-printed)
and an append-only journal at
<dir>/<uuid>.journal.jsonl
(one JSON object per line). The directory is created automatically on first save or
append if it does not exist.
There is no in-memory-only mode in this version — FileIdentityStore
always reads and writes disk files. The SDK does not currently ship an in-memory or
database-backed store adapter, but the constructor pattern is easy to extend by
implementing the same save /
load /
appendJournal /
readJournal interface.
{
"core": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "ResearchAgent",
"purpose": "Summarize academic papers on AI safety",
"createdAt": "2026-05-19T10:00:00.000Z",
"fingerprint": "a3f1c2d4e5b6a7c8"
},
"mutableState": {
"currentTask": "paper-review-2026-05"
},
"version": 2,
"updatedAt": "2026-05-19T10:05:00.000Z"
}
A hosted identity dashboard with multi-agent management, team access, drift history visualization, and remote retention is a roadmap item. It is not currently built or available. Python SDK support is also roadmap. What is available today is the local Node / TypeScript SDK and the file-backed storage adapter.
What Identity Engine SDK does and does not do
- Create a structured agent identity with an immutable core (id, name, purpose, createdAt, fingerprint)
-
Persist evolving mutable state and version history to a local JSON file via
FileIdentityStore - Append journal entries to a local JSONL file for state updates, drift checks, and arbitrary notes
- Run deterministic lexical drift checks comparing recent behavior text against the agent's purpose string
-
Return structured
DriftCheckResultwith alignment score, drift score, and aligned boolean - List, load, and delete identities by UUID from the local store directory
- Provide a hosted dashboard or team account system (roadmap)
- Provide a Python package or Python SDK support (roadmap)
- Support multi-user or team identity management
- Provide compliance-grade or legal identity proofing of any kind
- Perform legal or person identity verification — this SDK is for agent identity and state continuity only
- Guarantee drift prevention — only detection. A high drift score signals divergence but does not stop or correct agent behavior
Get early access to Identity Engine SDK
The local Node / TypeScript SDK is available now for private testing. A hosted identity dashboard with multi-agent management, team access, and drift visualization is in development. Leave your details and describe what you are building — we will reach out when hosted access and the Python SDK open.