Sentinel's default monitors track action rates, denial rates, and tool distribution. For domain-specific monitoring, you can add custom monitors that track metrics unique to your application.
Add custom monitors when you need to track:
A custom monitor has:
const guard = createGuard({
policy,
sentinel: {
enabled: true,
customMonitors: [
{
name: 'spending_rate',
extract: (receipt) => {
if (receipt.tool === 'payment.send') {
return receipt.args.amount;
}
return 0;
},
detector: {
ewma: { alpha: 0.3, sigmaThreshold: 2.5 },
cusum: { slack: 50, threshold: 500 },
},
aggregate: 'sum', // Sum values in the window
windowSize: 3600_000, // 1-hour window
},
{
name: 'data_read_volume',
extract: (receipt) => {
if (receipt.tool === 'file.read' && receipt.action === 'allow') {
return receipt.args.size || 1;
}
return 0;
},
detector: {
ewma: { alpha: 0.5, sigmaThreshold: 3.0 },
},
aggregate: 'sum',
windowSize: 60_000, // 1-minute window
},
{
name: 'external_comms',
extract: (receipt) => {
if (['email.send', 'slack.post', 'http.request'].includes(receipt.tool)) {
return 1;
}
return 0;
},
detector: {
cusum: { slack: 1, threshold: 10 },
},
aggregate: 'count',
windowSize: 300_000, // 5-minute window
},
],
onAlert: (alert) => {
if (alert.monitor === 'spending_rate') {
notifyFinanceTeam(alert);
} else if (alert.monitor === 'external_comms') {
notifySecurityTeam(alert);
}
}
}
});
onAlert callback fires.Write unit tests to verify that your monitors detect the anomalies you care about:
test('spending monitor detects rapid spending', () => {
const sentinel = createSentinel({ customMonitors: [spendingMonitor] });
// Simulate normal spending
for (let i = 0; i < 100; i++) {
sentinel.record({ tool: 'payment.send', args: { amount: 10 }, action: 'allow' });
}
// Simulate abnormal spending
const alerts = [];
sentinel.onAlert = (a) => alerts.push(a);
for (let i = 0; i < 10; i++) {
sentinel.record({ tool: 'payment.send', args: { amount: 500 }, action: 'allow' });
}
expect(alerts.length).toBeGreaterThan(0);
expect(alerts[0].monitor).toBe('spending_rate');
});
Custom monitors add a small amount of processing to each receipt. Each monitor performs one metric extraction and one statistical update per receipt. For most deployments, even 10 custom monitors add negligible overhead (under 100 microseconds per receipt).
Explore more guides on AI agent safety, prompt injection, and building secure systems.
View All Guides