Skip to main content

What anomaly detection does

KavachOS scans the audit log for behavioral patterns that suggest an agent is operating outside its intended scope. The most common signal is a cluster of denied calls that match privilege escalation patterns, an agent repeatedly attempting to access resources it was never granted. Anomaly detection is not a background process. You call scan() and get back a list of findings at that point in time. This keeps the system predictable: there are no background threads, no persistent state, and no surprise side effects.

Anomaly types

scan() queries audit logs directly, it is not a background process and does not push alerts. Call it from a scheduled job, a webhook handler, or a dashboard endpoint.

Anomaly fields

string
The agent where the anomaly was detected.
'privilege_escalation' | 'high_denial_rate' | 'rapid_fire' | 'unusual_resource_access' | 'off_hours_activity'
Classification of the detected pattern.
'critical' | 'warning' | 'info'
How urgent the finding is.
string
Human-readable explanation of what was observed.
number
Number of matching events in the scanned window.
string
ISO timestamp of when the scan ran.
AuditEntry[]
The specific audit log entries that triggered this finding.

AnomalyConfig options

Date
Start of the window to scan. Defaults to 24 hours ago.
Date
End of the window to scan. Defaults to now.
number
Denial rate percentage above which high_denial_rate fires. Default is 20.
number
Calls per hour above which rapid_fire fires. Default is 100.
string
Scope the scan to a single agent. Omit to scan all agents.

Code examples

Scan a single agent for anomalies

Get a denial-rate summary for all agents

Act on critical findings

The most effective response to a privilege escalation detection is to pause the agent while you investigate:
agent.revoke() is permanent. If you want to temporarily suspend an agent and restore it later, create a new agent with the same configuration instead of revoking.

Use trust scores as the anomaly aggregate

The anomalyCount field on a trust score is a pre-computed count of privilege escalation attempts, updated each time computeScore runs. It is a cheaper signal than a full scan when you only need the count:

Next steps

Trust scoring

Translate anomaly counts into a graduated trust level.

Approval flows

Route flagged agents through human review before they act.

Audit trail

Query the raw log data that anomaly detection reads.
Last modified on April 18, 2026