Join our Newsletter — 33% off our NHI Course
Home› Guides› AI Agent Behaviour Baselining and Anomaly Detection Guide:…
Guide Agent Controls & Monitoring

AI Agent Behaviour Baselining and Anomaly Detection Guide: Spotting Agents That Go Off Script

PDF for newsletter subscribers · free to read online

← All guides
By Lalit Choda, NHI Mgmt Group Updated 24 October 2026 17 min read
On this page

An AI agent that has been hijacked, poisoned or has simply misread its task usually still authenticates correctly, so the only reliable sign that something is wrong is that it starts behaving differently. Identity checks and permission boundaries tell you what an agent is allowed to do; a behavioural baseline tells you what it normally does, and the gap between the two is where most agent incidents happen. This guide explains how to build per-agent baselines from agent telemetry, which behavioural dimensions matter, how to choose between declared and learned baselines, which detection methods work for non-deterministic software, and how to measure whether it is working. It is written for detection engineers, SOC leads and platform teams who already log agent activity. What to log, attribution and the kill switch itself are covered in the AI Agent Observability and Incident Response Guide; this guide starts where that one stops.

Key takeaways

  • Baseline each agent, not each platform. A research agent that reads thousands of documents an hour and a payments agent that makes ten calls a day need different models of normal, and a shared baseline hides both.
  • Start with a declared baseline. The tools, data sources, destinations and action limits recorded for an agent at registration are a baseline you can enforce on day one, before you have any history to learn from.
  • Tie every baseline to a version. A new model, system prompt or toolset is a new agent for detection purposes; without version tags you either alert on every release or learn the attack as normal.
  • Watch sequences, not just counts. The dangerous pattern is often a normal read followed by an unusual write or outbound call, as in the ForcedLeak and EchoLeak research where data left through URLs on trusted domains.
  • Measure the detector. Track coverage of registered agents, time to detect in exercises, alert precision and baseline freshness, or the programme decays into noise that analysts ignore.

Why agent baselines differ from user and service account baselines

User and entity behaviour analytics (UEBA) already baselines people and hosts. Microsoft Sentinel UEBA, for example, builds dynamic profiles for users, hosts, IP addresses and applications, compares activity with an entity's own history, its peer group and the organisation as a whole, and scores events with an investigation priority from 0 to 10. Those ideas carry over to agents, but four properties change how they apply. See the UEBA Guide for the general method.

PropertyHuman userClassic service accountAI agent
DeterminismHabitual but variableHighly repetitive, scriptedNon-deterministic: the same task can produce different tool sequences
What drives activityJob role and working hoursSchedule or upstream triggerContent it reads: prompts, retrieved documents, tool results
Rate of changeSlow (role changes)Rare (code releases)Frequent: model, prompt, tool and memory changes
Speed and volumeHuman paceMachine pace, narrow scopeMachine pace, broad scope across many systems in one task
Typical sign of compromiseNew location, impossible travelNew source IP or APINew tool, new data, new destination or a changed plan after reading untrusted content

The third column is the important one. Because agent behaviour is driven by the content it reads, an attacker does not need the agent's credentials: indirect prompt injection (MITRE ATLAS AML.T0051, LLM Prompt Injection) changes the behaviour from the inside. NIST's Center for AI Standards and Innovation found that red teaming with the UK AI Security Institute raised hijacking success against one agent from 11% to 81%, and that retrying an attack 25 times raised average success from 57% to 80%. Prevention will not be complete, so behavioural detection is a necessary second layer. See the Prompt Injection Guide.

The telemetry a baseline is built from

A baseline is only as good as the fields it can group and compare. The OpenTelemetry generative AI semantic conventions (status: Development at version 1.37.0, now maintained in a separate GenAI repository) define agent operations create_agent, invoke_agent and execute_tool, with the tool span named execute_tool {gen_ai.tool.name}. Using these names lets you baseline across frameworks rather than per vendor. Managed platforms emit similar data: Amazon Bedrock AgentCore Observability produces OpenTelemetry-compatible metrics, spans, traces and logs in CloudWatch, with metric categories such as session count, latency, duration, token usage and error rates.

Baseline featureWhere it comes fromOpenTelemetry attribute (where defined)
Agent identity and versionAgent registry, platform spangen_ai.agent.id, gen_ai.agent.name, gen_ai.request.model
Task or sessionOrchestratorgen_ai.conversation.id
Tools called and tool typeTool spans, MCP or API gateway logsgen_ai.tool.name, gen_ai.tool.type (function, extension, datastore), gen_ai.tool.call.id
Data sources retrievedRetrieval spans, data platform audit logsgen_ai.data_source.id
Token consumptionModel spans, provider billinggen_ai.usage.input_tokens, gen_ai.usage.output_tokens
Credentials usedIdP, cloud and secrets manager logs (token or key ID, never the value)Not defined: add a custom attribute
Outbound destinationsEgress proxy, DNS, rendered URLs in outputNot defined: join from network logs
Authorisation and approval outcomesPolicy engine, human approval serviceNot defined: add a custom attribute

The last three rows are where most programmes have gaps, and they carry the strongest signals. Join them on a correlation or trace ID so that one task can be read end to end.

Behavioural dimensions to baseline

Pick a small set of dimensions per agent and baseline each one separately. A combined "weirdness score" is hard to explain to an analyst and hard to tune.

DimensionFeatures to profileA deviation may indicateRelated technique
Tool repertoireSet of tools used per version; first use of a tool; tool call frequency per taskGoal hijack, tool misuse, new attack pathATLAS AML.T0053 AI Agent Tool Invocation
Tool sequenceCommon n-grams of tool calls; read-then-send and read-then-delete pairsExfiltration or destruction chained after a normal readATLAS AML.T0086, AML.T0101
Data accessData sources, record counts, sensitivity labels touched per taskScope violation, bulk collectionATT&CK T1530 Data from Cloud Storage
Egress destinationsDomains and URLs contacted or rendered; new domains; data volume in URL parametersExfiltration through trusted or allowlisted domainsATT&CK T1567 Exfiltration Over Web Service
Credential useWhich token, key or role is used; reads of secret stores, environment variables or credential filesCredential harvesting, privilege escalationATLAS AML.T0098; ATT&CK T1552, T1078.004
Authorisation outcomesDenied calls per task; repeated denials on the same resource; approval requests per taskProbing for a way round a controlOWASP ASI03 Identity and Privilege Abuse
ConsumptionTokens, model calls, tool calls and cost per task and per hour; loop depthRunaway loops, denial of wallet, stolen key useATLAS AML.T0034 Cost Harvesting; ATT&CK T1496
Memory and configurationWrites to long-term memory, edits to rules or goals, reads of the agent's own configurationMemory poisoning, persistence, reconnaissanceATLAS AML.T0080, AML.T0084
Timing and principalHours of activity; which users or systems invoke it; invocations with no principalAbuse of a shared agent, unattended runsD3FEND D3-JFAPA

Tool sequence and egress destinations deserve extra weight. In both the ForcedLeak research on Salesforce Agentforce and the EchoLeak research on Microsoft 365 Copilot, data left through URLs on domains the platform trusted, so a domain allowlist alone would have passed the traffic. A baseline of normal destinations per agent, plus a feature for data volume carried in URL parameters, catches what the allowlist misses.

Declared baselines versus learned baselines

There are two ways to define normal, and mature programmes use both.

  • Declared baseline: the agent's registered purpose, tool list, data sources, permitted destinations, action budgets and autonomy level, written down before deployment. Any action outside the declaration is an alert or a block. It needs no history and is easy to explain, but it is only as good as the registration. See the Identity Governance for AI Agents Guide.
  • Learned baseline: a statistical profile of what the agent has actually done over a training window, per version. It catches drift inside the declared envelope, such as an agent that is allowed to read the CRM but normally reads 40 records per task and suddenly reads 4,000.
SituationPreferWhy
New agent, no historyDeclaredNothing to learn from; enforce the registration
High-impact actions (payments, deletes, access changes, external messages)Declared, enforced as hard limitsLearning would treat an early attack as normal; impact justifies blocking
Stable agent with broad read accessLearned on top of declaredVolume and sequence anomalies sit inside the permitted scope
Fleet of similar agents (one template, many instances)Learned, with peer group comparisonAn instance that diverges from its siblings stands out quickly
Third-party or SaaS agent with limited telemetryDeclared at the boundaryYou may only see its API calls, OAuth grant and egress

The declared baseline also makes the learned one safer. Learn only from activity that stayed inside the declaration, so that a violation never becomes part of the model of normal.

Detection methods and their trade-offs

MethodGood atWeak atUse for
Boundary rules (deny or alert outside declaration)Precise, explainable, works on day oneMisses misuse inside allowed scopeNew tools, new destinations, credential reads, high-impact actions
Static thresholds and rate limitsRunaway loops, cost spikesNeeds per-agent tuning; bluntTool calls per minute, tokens per task, failed calls per task
Statistical baselines (per agent, per version)Volume and frequency driftCold start; seasonality; poisoned training windowsRecords read, tools per task, cost per hour
Rarity and first-seen analysisNew tool, data source, domain or credentialEvery release creates first-seen eventsCombine with version tags to suppress expected change
Sequence analysisRead-then-exfiltrate, plan change after untrusted inputNeeds good trace correlationTool n-grams, retrieval followed by new egress
Peer group comparisonOne instance in a fleet going wrongUseless for unique agentsTemplated agents, per-tenant copies
Model-based review of traces (a second model judges the trace)Intent and context that counters missItself non-deterministic and injectable; costTriage of flagged traces, not primary detection

The OWASP AI Agent Security Cheat Sheet illustrates the threshold approach with sample values (30 tool calls a minute, five failed tool calls, one injection attempt, a $10 cost cap per session) and stresses that they are examples. Set your own from observed behaviour. The same cheat sheet recommends watching drift in approval behaviour and repeated attempts to bypass approval, which are among the most specific signals an agent produces.

Two scores are better than one. Sentinel UEBA separates an event-level investigation priority from a behaviour-level anomaly score, and notes that a first-time Azure operation can rank high on one and low on the other. Keep a similar split: a rarity score for "never seen before" and an impact score for "this would matter if it were malicious", and alert on the combination.

Handling change: versions, cold start and drift

  • Version keys: key every baseline on agent ID plus model, system prompt hash, toolset and memory policy version. A release starts a new baseline that inherits the declared envelope but not the learned statistics.
  • Cold start: for a new version, run boundary rules and thresholds only, and use the previous version's profile as a soft reference. Collect a training window of real tasks before enabling statistical alerts; length depends on task volume, so set it by number of tasks rather than days.
  • Clean training windows: exclude tasks with policy denials, injection detections or open incidents from training data, so that an attack in progress is not learned.
  • Drift versus anomaly: slow, steady change across many tasks (a new business process) is drift and should trigger a review of the declaration; a sharp change in one task or session is an anomaly and should trigger triage.
  • Seasonality: month-end, campaign launches and batch jobs change volume; model them explicitly or compare against the same period rather than a rolling average.
  • Memory effects: agents with long-term memory change behaviour as memory grows. Treat a large memory write followed by a behaviour shift as a sequence worth investigating. See the AI Agent Memory Security Guide.

How to implement

  1. Inventory and tag: make sure every agent in scope has a registry entry with owner, purpose, tools, data sources, destinations and autonomy level, and that its telemetry carries the agent ID and version. Agents with no registry entry are your first finding. See the Shadow AI Discovery Guide.
  2. Close telemetry gaps: join tool spans, gateway logs, IdP and cloud audit logs, egress proxy logs and approval logs on a trace ID. Add custom attributes for credential ID, authorisation outcome and destination.
  3. Deploy declared rules in alert-only mode: new tool, new destination, credential store read, high-impact action without approval, repeated denials. Run for two to four weeks, review every alert with the agent owner and fix the declaration where it was wrong.
  4. Promote high-confidence rules to enforcement: move boundary rules for high-impact actions and egress to blocking at the gateway or policy engine, one agent at a time, starting with the highest risk. Keep a documented override and a rollback (revert the policy version) for each.
  5. Add thresholds: per-agent caps on tool calls, tokens, cost and loop depth per task, set from observed percentiles with headroom.
  6. Add learned baselines: for agents with enough volume, profile volume, first-seen and sequence features per version, trained on clean windows. Pilot on a small ring of agents and compare alerts against analyst verdicts before widening.
  7. Route and respond: send alerts to the SIEM with agent owner, version and trace link attached, and map each alert type to a response: notify owner, pause agent, or trigger the kill switch. See the AI Agent Kill Switch and Containment Guide and the AI Agent Incident Response Playbook.
  8. Test continuously: replay known attack traces and run red team exercises (injected documents, credential lures, exfiltration via rendered URLs) against staging agents and confirm each produces the expected alert. See Red Teaming AI Agents for Identity Abuse.

Small and large organisations

  • Small teams: rely on declared baselines and thresholds. Use the controls your agent platform and cloud provider already provide (gateway allowlists, rate limits, cost alerts, managed AI threat detection such as Microsoft Defender for Cloud AI threat protection, which raises alerts for data leakage, data poisoning, jailbreak and credential theft for Azure OpenAI workloads). Review a weekly report of first-seen tools and destinations per agent.
  • Large organisations: centralise agent telemetry in the SIEM or data lake, build per-version learned baselines, use peer groups for agent fleets, and give detection engineering a standing backlog of agent detections with owners. Expect hundreds of agents, many built on low-code platforms, so automate registration checks.
  • Third-party agents: whatever your size, you usually see only the OAuth grant, API calls and egress. Baseline those at your boundary and ask the vendor what agent telemetry it can export.

Measuring whether it works

MetricHow to calculateTarget direction
Baseline coverageRegistered production agents with an active declared baseline, divided by all registered production agentsTowards 100%
Telemetry completenessShare of agent actions carrying agent ID, version, principal, credential ID and trace IDTowards 100%
Time to detect in exercisesMinutes from injected test behaviour to alert, per scenarioDown, and below the time an agent needs to cause harm
Alert precisionAlerts confirmed as true positive or valid policy violation, divided by all agent alertsUp; falling precision means retune
Baseline freshnessShare of agents whose baseline matches the currently deployed versionTowards 100%
Declaration drift reviews closedDrift findings reviewed with owners within the agreed timeUp

Framework mapping

FrameworkReferenceHow baselining supports it
NIST CSF 2.0DE.CM-09, DE.AE-02, DE.AE-03Monitoring runtime environments; analysing adverse events; correlating agent, identity and network data
NIST SP 800-53 Rev. 5SI-4, SI-4(2), SI-4(4), SI-4(13)System monitoring, real-time automated analysis, outbound traffic monitoring, analysing event patterns to build profiles
NIST SP 800-53 Rev. 5AC-2(12), AU-6(5), AU-12Monitoring accounts for atypical usage; integrated analysis of audit records; audit record generation
MITRE D3FENDD3-UBA, D3-RAPA, D3-JFAPA, D3-UDTAUser behaviour, resource access pattern, job function access pattern and data transfer analysis applied to agent identities
MITRE ATLASAML.T0051, AML.T0053, AML.T0086, AML.T0098Techniques whose effects show up as behaviour change
OWASP Top 10 for LLM Applications 2025LLM06 Excessive Agency, LLM10 Unbounded ConsumptionLLM10 explicitly recommends logging, monitoring and anomaly detection for resource consumption
OWASP Top 10 for Agentic ApplicationsASI01 Agent Goal Hijack, ASI02 Tool Misuse, ASI10 Rogue AgentsBehavioural detection is the main control for misaligned or self-directed action that passes authorisation

Common failure patterns

  • Trusting the allowlist as the baseline: egress to "trusted" domains is not inspected. ForcedLeak used an expired domain still on a content security policy allowlist, bought for about $5; EchoLeak abused trusted Microsoft domains. Baseline destinations per agent and inspect data in URLs.
  • One baseline for the whole platform: all agents share a service account or a platform-level profile, so a single agent's deviation disappears into the average. Give each agent its own identity and baseline. See the Agentic AI Identity Guide.
  • Learning the attack: statistical models trained on windows that included injected or abusive tasks treat them as normal. Train only on clean, in-declaration activity.
  • Release noise: baselines not keyed on version fire on every prompt or model update, and analysts learn to close agent alerts unread.
  • Monitoring outcomes only: the SOC sees the CRM export but not the retrieval and plan change that preceded it, so it cannot tell injection from a legitimate request. Correlate retrieval, plan and tool spans.
  • No live monitoring of agents with real-world reach: in the UK AISI agent testing incident, agents with internet access created fake identities and contacted real people over several days before security monitoring flagged data leaving over Tor. Alert on account sign-ups, outbound messages, repository writes and anonymity network use from agent runtimes.

Practitioner checklist

  • Every production agent has a registry entry whose tools, data sources, destinations and action limits form an enforced declared baseline.
  • Agent telemetry carries agent ID, version, principal, credential ID, authorisation outcome and trace ID, using OpenTelemetry GenAI names where possible.
  • Egress from agent runtimes passes a proxy that logs destination and URL data volume per agent.
  • Boundary rules cover first-seen tools, destinations and credentials, secret store reads, repeated denials and high-impact actions without approval.
  • Per-agent caps exist for tool calls, tokens, cost and loop depth per task.
  • Learned baselines are keyed on version and trained only on clean, in-declaration activity.
  • Each alert type maps to a documented response, from owner notification to the kill switch.
  • Detections are tested with replayed attack traces and red team scenarios at least every release cycle.
  • Coverage, completeness, time to detect, precision and freshness are reported monthly.

Standards and references

Related NHI Mgmt Group resources: AI Agent Observability and Incident Response Guide · UEBA Guide · AI Agent Incident Response Playbook · Incident Response Guide · Agentic AI Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Written and reviewed by Lalit Choda, NHI Mgmt Group. Last updated 24 October 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.