Skip to content
A graphite ring examining a violet path among branching lines on folded paper.
Zaun Research / Understand behavior

Understanding how agents act on harmful behaviors.

The same tool call can support routine work or a harmful task. Our research combines intent, actions and prior events to distinguish the two.

01 / Event context

Learning the shape of normal.

Agents run shell commands, edit files, call MCP tools and fetch pages. Most of these actions are ordinary work. Distinguishing the exceptions requires context: what was requested, what the agent did, and what similar events turned out to be.

ABBA (Agentic Behavioral Monitoring) compares each event with labeled examples of past behavior. If the nearby examples provide strong benign evidence, a rule called the confidence gate resolves the event. Otherwise, an LLM examines it. We measure detection quality, time to verdict and classification cost.

One command. Three different contexts.cat .env
Debugging

Check whether this project has the environment variables it needs to start.

Consistent with debugging

The request explains the configuration read. Subsequent actions and access policy still matter.

Credential export

Read the project credentials and send them to an unrelated external destination.

Potential credential exfiltration

The read supports a transfer of credentials. That intent is absent from the command alone.

Missing prompt

The original request is unavailable.

Insufficient context

The command does not establish why the file was read. A confident benign assessment is unsupported.

Authored examples illustrating the role of intent, not live classifier output.

What changes when intent is included?

Nearby events agree on their labels more often when the input includes both the request and the action.

Tool metadata only≈39%
Prompt + action≈80%
Neighborhood label agreement in the input ablation. The encoder is held fixed; this measures input representation.

Build the text the model sees

Secrets are redacted before the event is rendered. We then join labeled fields in a consistent order, keeping the request next to the action it produced. The same format and task prefix are used in training, index construction and live queries.

Event renderSecrets already redacted
User’s Prompt:
Check the configuration needed to run integration tests.
Tool:
shell
Input:
cat .env
MCP:
Not reported
Approval:
User approved
Output:
APP_TOKEN=[REDACTED]
2,000 characters

Maximum per segment. Long segments keep their head and tail, separated by a constant elision marker.

Intent and action first

The request, tool and arguments lead the representation. Optional metadata follows in a fixed order.

Output last, when available

Tool output can contain an injected instruction. Include it without displacing the intent-and-action lead.

Authored example of the field order. Missing or truncated context limits what the representation can establish.
02 / The decision

From an event to a decision.

An embedding is a list of numbers representing an event. Nearby embeddings describe similar events. The gate checks whether enough of those neighbors agree on a benign label; limited or conflicting evidence goes to LLM classification.

Evidence determines the path.

The encoder stays the same. What changes is the labeled neighborhood returned by retrieval.

Agreeing labels

Enough nearby labels agree on benign behavior.

Resolve in the gate

Few neighbors

Too few events support the decision.

LLM classification

Mixed labels

Nearby events disagree about the behavior.

LLM classification
New eventBenignAdverse
Enough benign evidence

Resolve and record.

The gate path takes about 43 ms in this evaluation. A random 1% still goes to the classifier for an audit.

Insufficient or conflicting evidence

Examine the event in context.

The LLM classifier checks the event against context and policy. The classification baseline is about 954 ms.

Conceptual neighborhoods, not measured embeddings. Timings describe the reported evaluation setup.

What the LLM adds

The LLM classifier evaluates the event and its retrieved context. A harmful finding identifies a MITRE ATLAS tactic, a category of adversarial AI behavior, and the relevant organizational policy clause when one is available. These findings produce alerts.

In this evaluation, the gate path takes about 43 ms. The LLM classification baseline takes about 954 ms and costs $490 per million events. Resolving an event in the gate saves an LLM call, while still using embedding and retrieval compute.

After the online decision

Audit decisions, describe recurring behavior, and correct the local evidence.

  1. 01 / Shadow audit

    Randomly classify 1%.

    A random 1% of gate-resolved events still goes to the classifier. Disagreements are surfaced and the event’s local label is corrected.

  2. 02 / Nightly clustering

    Name recurring behavior.

    Unsupervised hierarchical clustering groups normalized vectors. One model call per cluster assigns a readable name, which also supplies neighbor context to later classifier calls.

  3. 03 / Local feedback

    Keep the correction.

    Verdicts and analyst corrections update the event’s point. Closing a group investigation relabels its members. Shared encoder weights stay unchanged.

The dot grid illustrates the 1% sampling rate. Audits estimate gate misses from the sampled events; they do not inspect every gate decision.
03 / Model training

A sentence transformer for agent behavior.

Zaun’s embedding model is a sentence transformer fine-tuned for this classification task. It maps the event text to one vector in a single forward pass. Fine-tuning teaches that space to organize events by behavior, including when similar commands serve different purposes.

One rendered event
IntentUser prompt
ActionTool and input
ContextOutput and available metadata
Zaun embedding modelFine-tuned
sentence transformer
z = fθ(event)
One event vector[v₁, v₂, …, vₙ]

Used to retrieve
labeled neighbors

The rendering format and task prefix stay consistent across training, index construction and queries. The vector notation is symbolic.

Learn from pairs and counterexamples

Training starts with an anchor event and two kinds of comparison: a positive example with the same behavior, and a negative with a different one. Contrastive learning pulls the positive closer and pushes the negative away. A hard negative uses similar wording or tools, so intent must supply the distinction.

The training signal

The positive moves toward the anchor. The hard negative moves away, even though it uses the same command.

Anchor event

Check whether this project has the environment variables it needs to start.

cat .env
Positive pair

Different wording, same behavior

Inspect the local configuration to diagnose the startup failure.

cat .env
Hard negative

Same command, different intent

Read the project credentials and send them to an unrelated external destination.

cat .env
Authored examples of the contrastive objective. Positions illustrate the training signal, not measured embeddings or a fine-tuning result.

Build batches that test the distinction

We use cached Multiple Negatives Ranking Loss. For each anchor, the matching positive is compared with positives from other pairs in the batch, which act as additional negatives. Gradient caching lets us make these comparisons across a larger effective batch without retaining every activation at once.

Explicit hard negatives supplement those batch comparisons. A legitimate update to an agent’s configuration can resemble a persistence attempt in the same directory. The same tool and argument shape can also appear under an ordinary request or an injected instruction. We mine these comparisons from the reference corpus, its measured false positives and neighboring behavior groups.

Every reference example records where its label came from. We separately exclude model-authored labels during evaluation to check for learned classifier errors. Customer events and local analyst corrections stay outside shared model training.

Keep shorter vectors useful

Matryoshka training applies the same contrastive objective to the full vector and to shorter prefixes, the first portion of its coordinates. This trains the model to retain useful similarity relationships at smaller storage sizes. We evaluate each size for label agreement, retrieval quality, memory use and CPU latency.

Learn at several vector lengths.

Each shorter representation keeps the beginning of the same vector. Training tests the behavioral relationships at every chosen length.

One encoder, several storage sizes
Short prefix
Longer prefix
Full vector
Blocks illustrate nested prefixes. They are not the model’s actual dimensions or measured vector values.

Preserve retrieval quality when the model changes

We also train on generic public text with a distillation term that limits changes to its existing embeddings. This helps preserve general retrieval quality for other parts of the product that use the encoder.

The model, event format and task prefix together define the index’s coordinate system. An update creates a new versioned collection and a freshly embedded reference index. Each collection uses one encoder version. Sparse local evidence continues to route events to classification during the transition.

Before release, we check performance on withheld examples and an unseen source, false positives at fixed recall in a held-out evaluation environment, general retrieval quality and CPU latency. These checks evaluate the encoder update independently of index size.

04 / Data and privacy

Reference data and isolation

No customer data was used to train AI models. Fine-tuning uses synthetic and public-benchmark reference examples, hand-labeled by internal and third-party personnel. Organization activity is indexed separately for each organization and agent product.

The reference corpus
Hand-labeled by
internal & third-party personnel

Reference examples support fine-tuning, index seeding and evaluation, with training and holdout splits kept separate.

Organization-specific index

Separate indexes per environment

Each index resides in the organization’s environment. Events and labels are not pooled across organizations.

New events extend the local index; analyst corrections update its labels. These updates do not train shared model weights. A rolling retention window ages out live events. Versioned reference seeds are kept separately and do not expire with that window.

05 / Cold start

Starting with no local history.

A new organization has no past events to retrieve. ABBA searches a versioned reference collection alongside the organization’s own collection, while retaining the same rule: insufficient evidence goes to classification.

Reference events
≈20,000
Synthetic & benchmark sessions
≈4,500
Adverse events
≈1,100
ATLAS tactics
14

Reference collection

Synthetic & public-benchmark examples

Versioned seeds, retained across the live window

Local collection

One organization, one agent product

Private activity, rolling retention window
  1. Reference only

    No local history yet.

    The reference collection supplies labeled behavior examples. Without sufficient agreeing benign neighbors, a new event goes to the classifier.

  2. Local history

    Routine work adds local evidence.

    Recurring workflows can form benign neighborhoods. Sparse or conflicting evidence still escalates, even when other parts of the space are familiar.

  3. Corrected labels

    A review changes the next lookup.

    A corrected point changes the evidence returned to future queries nearby. The update stays in this organization’s index and does not retrain shared model weights.

Conceptual collection states, not a measured timeline or embedding projection. Point counts do not represent corpus proportions.

Two collections, different jobs

Reference seeds supply labeled examples of known behaviors, including adverse events a particular organization may never have seen. Seeds are drawn as complete sessions, balanced across tactics and accompanied by benign examples. Each example retains its source and label provenance.

Live points supply the local context a reference corpus cannot: the organization’s repositories, internal tools and recurring workflows. As labeled history accumulates, it can provide evidence for more gate decisions. Analyst and investigation corrections relabel those local points. Closing a group of events updates every member’s label.

The reference collection is refreshed with the corpus version without modifying live points. The live collection follows its own retention window. Coverage depends on the activity and labels available in an environment. The following experiment measures reference evidence; it does not predict how many days a customer’s index takes to fill.

06 / Results

Measuring the value of reference data.

We populate the index with 0 to 16,500 labeled reference events, called seeds. Each index is tested against the same holdout: examples kept out of training and seeding. The encoder and classifier stay fixed, so the experiment isolates the effect of adding reference evidence.

Fixed encoder and classifier

Eight seed counts. One holdout.

Each plot follows the same experiment from zero to 16,500 reference examples. Only the reference evidence available to retrieval changes.

Resolved in gate

0%17.7%
Events resolved in the gate (%), from 0% to 17.7% across the seed sweep0102008k16.5kLabeled reference examples
Fraction of events resolved by the confidence gate without an additional LLM call.

ROC-AUC

0.500.92
ROC-AUC, from 0.50 to 0.92 across the seed sweep0.500.751.0008k16.5kLabeled reference examples
How well the scores separate benign and adverse events across decision thresholds. ROC-AUC is the area under the receiver operating characteristic curve.

Verdict time

954 ms793 ms
Mean time to verdict (ms), from 954 ms to 793 ms across the seed sweep750875100008k16.5kLabeled reference examples
Mean latency across the gate and LLM paths in the seed sweep.

LLM cost / million

$490$403
Classifier cost per million events ($), from $490 to $403 across the seed sweep375437.550008k16.5kLabeled reference examples
Classifier cost per million events in this evaluation. Compute and infrastructure costs are not included.
Full reference-corpus seed sweep. Lines connect observed values. Approximately zero gate share at 500 examples is plotted at zero.
ExampleskNN accuracyGate shareROC-AUCMean verdictCost / million
0n/a0%0.50954 ms$490
12548%0%0.65954 ms$490
50076%≈0%0.70954 ms$490
1,00097%3.7%0.77920 ms$472
2,00098%6.0%0.83900 ms$461
4,00098.5%9.6%0.88867 ms$443
8,00099%13.1%0.92835 ms$426
16,50099.2%17.7%0.92793 ms$403

Synthetic and public-benchmark data; a frozen holdout excluded from seeding. Reported latency and cost apply to this evaluation setup. Per-draw spread is not supplied, so the plots have no error bands.

What changes as the index fills

Across this sweep, gate share rises from 0% to 17.7%. Mean time to verdict falls from 954 ms to 793 ms, and classifier cost falls from $490 to $403 per million events. The encoder and classifier stay fixed; the change is the evidence available to retrieval.

Seeded kNN accuracy reaches 99.2% at 16,500 examples. ROC-AUC reaches 0.92 at 8,000 examples and remains there at 16,500. These are different measurements: neighborhood label accuracy does not establish end-to-end detection recall.

07 / Evaluation

How we test the method.

The evaluation separates three changes: the text sent to the model, the model’s weights, and the examples stored in the index. It also checks whether repeated templates or unreliable labels could inflate a score.

Keep the experiments separate

Better inputs, better model weights and more reference examples can each improve the system. Each experiment changes one of these while holding the others fixed.

Event representation
ChangeThe text sent to the encoderKeep fixedThe encoder
≈39% → ≈80%Neighborhood label agreement
Index seeding
ChangeThe number of reference examplesKeep fixedEncoder and LLM classifier
8 seed countsFull results in the sweep above
Encoder fine-tuning
ChangeThe model’s learned weightsEvaluateBehavior and retrieval quality
Method describedNo before-and-after uplift reported here

Track the source of every label

The corpus includes synthetic sessions, public-code work, AgentDojo, OASB, ASB and generated adverse trajectories. Internal and third-party personnel hand-label reference examples. Each row records its source, how its label was assigned, and its ATLAS tactic where applicable.

Benchmark labels, model-generated verdicts and labels assigned by rules are tracked separately. Rule-based labels are used for reporting slices, with no reference-gold status. An exclusion run tests the effect of model-authored labels. Local customer corrections remain in private retrieval indexes.

A different session can still be the same example

Adjacent steps in one agent session share context, so they belong on the same side of the train-test split. Different sessions may also reuse a template with changed identifiers or numbers. We group those near-duplicates before splitting the data.

An earlier campaign exposed the scale of this problem: 97.8% of holdout rows had a template twin in the seed pool at cosine similarity 0.999. Approximately 4,500 sessions reduced to about 900 independent content groups. These are findings from a leakage audit, not detector performance scores.

Group the reference corpusKeep complete sessions and near-duplicate examples together.
Development data

Develop, then calibrate

Training and seed examples remain on this side. A separate validation fold sets the threshold before holdout scoring.

Frozen holdout

Evaluate on separate sessions

Holdout examples are excluded from training and seeding. Their labels are used to score predictions.

Each outlined group represents a session or a family of near-duplicate examples. The diagram illustrates separation, not dataset proportions.

Evaluate difficult cases separately

The holdout is fixed and versioned. Its examples never enter training or the seed index. We preserve the mix of data sources, including public-code work, and examine several difficult cases individually.

Indirect prompt injection
Attacker-influenced tool output can change the agent’s next action. These events get a separate detection score.
Benign configuration writes
Legitimate edits can resemble persistence attempts. Keep them in proportion across splits to test false positives.
Withheld intent
Some adverse goals are absent from the visible event. Retain and report these examples separately, flag them as unattainable from the available context, and exclude them from tuning.

Ambiguous labels are excluded from both sides of the split. This is separate from withheld-intent cases, where the label is known but the event lacks the evidence needed to infer it.

Repeat against the same holdout

At each seed count, the protocol uses five fixed random draws. Sampling keeps sessions intact, balances tactics and includes benign examples. A separate run uses the corpus’s natural proportions. We compare the mean and spread across draws.

The published table supplies one value per metric at each seed count, with no per-draw spread. The chart therefore has no error bands. Monthly reruns compare dated corpus versions against the same holdout to test whether added examples improve the measurements.

Check for shortcuts with negative controls

A high score is not sufficient evidence that the model recognizes behavior. We also test whether the result depends on meaningful labels and independent examples.

Shuffle the labels
Random labels should remove the useful relationship between an event and its neighbors. A strong result after shuffling suggests another explanation.
Exclude self-matches
An evaluation event cannot retrieve itself. This checks that the score depends on other examples rather than the query’s own stored label.
Remove model-authored labels
Re-run without model-authored labels. Agreement with a classifier’s own labels is not independent evidence that those labels are correct.

Read each measurement in context

A correct neighbor label, a caught attack and an avoided LLM call are different outcomes. These measurements describe different parts of the system.

Neighborhood quality
Purity at k is the fraction of the k nearest examples that share an event’s label. Seeded kNN accuracy instead measures whether the neighbors predict the held-out event’s label correctly.
Detection quality
ROC-AUC measures discrimination across thresholds. We fit a threshold for 99.9% specificity on validation data, then measure holdout recall. Specificity is the share of benign events correctly identified as benign; recall is the share of adverse events detected. That recall value is not reported here.
Gate behavior
Gate share measures how often the index supports a confident benign decision. Random 1% shadow audits classify sampled events to estimate what the gate may miss.
Latency and cost
Mean time to verdict includes the gate and classification paths. Reported classifier costs apply to this evaluation setup and exclude compute and infrastructure costs.

What the results leave open

The seed sweep describes a reference-corpus experiment. It does not establish the time a particular organization needs to reach the same coverage, or guarantee the same latency and cost under another workload. Aggregate results also cannot show every failure mode. Per-tactic evaluation, held-out workflows and audits of gate-resolved events remain necessary for understanding where the method is reliable.

Further experiments

Proposed extensions to the current pipeline.

  1. 01
    Transfer across workflows

    Measure neighborhood quality on held-out tools and task types.

  2. 02
    Gate calibration

    Replace hand-set neighborhood thresholds with a small model calibrated per environment.

  3. 03
    Smaller inference models

    Evaluate distillation to a smaller encoder against the same behavior and general retrieval checks.