Autonomous AI agents (systems that iteratively plan, invoke external tools, and act upon the results of prior steps without continuous human supervision) are moving rapidly from research prototypes to production deployments. Agents built on large language model (LLM) backends now write and execute code, query databases, send communications, and manage financial transactions on behalf of their users (Mialon et al., 2023; Yao et al., 2023). This capability expansion creates a corresponding expansion of the attack surface and governance challenge. An agent that can browse the web can exfiltrate data. An agent that can write code can introduce vulnerabilities. An agent that can send email can conduct social engineering.
The dominant response to these risks has been pre-deployment evaluation: safety benchmarks that probe model behavior on standardized harmful inputs, red-teaming exercises where human experts attempt to elicit unsafe behaviors, and alignment fine-tuning that nudges model outputs away from policy-violating completions (Ganguli et al., 2022; Perez et al., 2022). These approaches share a fundamental limitation: they characterize model behavior in controlled conditions, not production conditions. The distribution of actual user inputs, tool responses, and chained context windows encountered at runtime is vastly larger and more adversarially structured than any benchmark can capture.
Runtime governance (monitoring and intervention at inference time) is therefore a necessary complement to static evaluation. This paper addresses the question: what should a runtime behavioral monitoring framework for autonomous AI agents look like? We propose and describe an architecture consisting of three integrated components, detail their implementation in open-source tooling, and report evaluation results.
Our contributions are as follows:
Modern LLM-based agents follow a perceive-plan-act loop. At each step, the agent receives an observation (tool output, user message, or memory retrieval), updates its internal context window, generates a plan or action, and dispatches a tool call or produces a final response. ReAct (Yao et al., 2023), Toolformer (Schick et al., 2023), and function-calling APIs from commercial providers have established the dominant patterns. Multi-agent systems add coordination complexity: individual agents may delegate subtasks to peer agents, creating nested call graphs that are difficult to inspect holistically.
Pre-deployment safety measures include Constitutional AI (Bai et al., 2022), RLHF-based alignment, and output classifiers that filter model responses. These operate outside the agent loop: they shape what the LLM will say but cannot intercept actions that a compliant-seeming response will trigger. Sandboxing approaches isolate agent execution environments but do not monitor the semantic content of actions. Process-level isolation prevents filesystem escapes but does not detect when an agent exfiltrates data through an authorized API call. Monitoring tools from the observability ecosystem (LangSmith, Weights & Biases, Langfuse) log agent traces but are primarily diagnostic rather than preventive.
Open Policy Agent (OPA) and Cedar (Amazon's authorization policy language) provide declarative policy frameworks for software systems, and both have been adapted for LLM application authorization (AWS Cedar, 2023). Agent-specific policy challenges, particularly the need to reason over multi-step action sequences and context-dependent tool permissions, are not well served by authorization frameworks designed for single-request access control. Our framework borrows from temporal logic verification and finite-state machine specifications to handle sequential action constraints.
We model an agent execution trace as a directed acyclic graph G = (V, E) where each vertex v ∈ V represents an agent event (tool invocation, response generation, memory read/write, or inter-agent message) and each edge (u, v) ∈ E represents a causal dependency between events. Each vertex carries a structured payload including: event type, timestamp, tool identifier, input parameters, output data, agent identity, and a cryptographic hash of the preceding event (forming a chain analogous to a blockchain).
A governance policy P is defined as a set of predicates over event sequences. A predicate may be temporal (e.g., "no tool of type DATA_EXFIL may follow a tool of type READ_PII within the same session"), resource-scoped (e.g., "writes to external_api:stripe are only permitted if prior event includes user_confirmation"), or rate-limited (e.g., "at most 50 web_browse calls per agent session"). Policy violations are defined as event sequences that falsify one or more predicates in P.
The runtime firewall is implemented as a middleware layer that wraps all tool dispatcher interfaces. Before any tool call is executed, the firewall: (1) extracts the call's structured parameters; (2) evaluates the proposed call against the policy graph given the current session's event history; (3) if approved, logs the event to the forensic ledger and passes the call through; (4) if denied, raises a PolicyViolationException with structured metadata and logs the attempted violation.
The firewall design prioritizes fail-closed behavior: any error in policy evaluation (including malformed policy rules or unexpected event types) results in denial rather than pass-through. This inverts the fail-open default of most middleware systems, at the cost of requiring thorough policy testing before deployment.
Beyond explicit policy rules, the behavioral anomaly detection engine identifies unusual action patterns that may indicate compromised agents, prompt injection attacks, or policy gaps. It operates as a second-pass analyzer over the event stream and employs two detection strategies:
Rule-based classifiers encode known attack patterns: prompt injection signatures, tool-chaining patterns associated with data exfiltration, anomalous recursion depths, and cross-agent message forgery patterns. These rules are expressed as regular expressions over event-type sequences and updated continuously as new attack patterns are documented.
Statistical anomaly detection builds a baseline behavioral profile for each agent type and session context, flagging sequences that deviate significantly from the empirical distribution. We use an isolation forest model trained on historical session traces, with a contamination parameter tuned to a target 1% false positive rate.
The forensic ledger records every agent event (approved, denied, and anomalous) in a hash-chained append-only log. Each entry includes the full event payload, the policy verdict, the evaluating policy version hash, and a SHA-256 hash of the previous entry. This structure ensures that any post-hoc modification of the ledger is detectable. Ledger entries are human-readable JSON and machine-parseable, supporting both compliance reporting workflows and programmatic incident investigation.
The ledger design is intentionally storage-agnostic: reference implementations use local file storage, SQLite, and cloud object storage (S3-compatible) backends, selectable by configuration.
We constructed a synthetic benchmark of 1,200 adversarial agent scenarios across six attack categories: prompt injection (n=280), data exfiltration via authorized APIs (n=220), privilege escalation through tool chaining (n=200), cross-agent message forgery (n=180), resource abuse (n=170), and policy gap exploitation (n=150). Each scenario consists of a multi-step agent session in which the adversarial behavior occurs at a variable position in the trace, ensuring the framework cannot exploit position bias.
| Attack Category | n | Detection Rate | False Positive Rate | Mean Latency (ms) |
|---|---|---|---|---|
| Prompt Injection | 280 | 97.1% | 0.8% | 6.2 |
| Data Exfiltration | 220 | 91.4% | 1.4% | 9.1 |
| Privilege Escalation | 200 | 96.0% | 0.9% | 8.8 |
| Message Forgery | 180 | 93.3% | 1.1% | 7.9 |
| Resource Abuse | 170 | 95.3% | 0.6% | 8.1 |
| Policy Gap Exploitation | 150 | 88.7% | 2.2% | 11.3 |
| Overall | 1,200 | 94.2% | 1.1% | 8.4 |
A primary design constraint for runtime governance is latency: overhead that exceeds acceptable thresholds will cause production deployments to bypass the framework entirely. Our target was sub-10ms mean interception latency. Across all benchmark scenarios, the mean policy evaluation latency was 8.4ms per tool call, with 95th percentile latency of 23.7ms driven by complex temporal policy predicates over long session histories. Policy gap exploitation scenarios show the highest latency due to the exhaustive policy matching required when no specific rule applies.
Several limitations warrant acknowledgment. First, the benchmark is synthetic; real-world adversarial agent scenarios may have distributional properties not captured in our construction. Second, the statistical anomaly detector requires historical session data to build meaningful baselines, limiting its utility in cold-start deployments. Third, policy expressiveness and detection coverage are in tension: more permissive policies reduce false positives but increase the policy gap exploitation attack surface. Finally, the framework does not currently address multi-model agent architectures where tool calls may be generated by multiple LLM backends with different behavioral profiles.
Three open-source projects implement the components described above:
Runtime behavioral monitoring represents a significant but underexplored layer of the AI governance stack. Pre-deployment evaluation and alignment training address what a model can do and what it is inclined to do; runtime monitoring addresses what it actually does in production. These three layers are complementary, not substitutive.
We see several directions for future work. Formal policy languages with decidable semantics would allow automated policy consistency checking (detecting contradictions and gaps before deployment). Integration with emerging AI Act compliance reporting workflows would make the forensic ledger directly useful for regulatory obligations. Extension to multi-modal agent systems (where actions may include image generation, audio synthesis, or video manipulation) requires new event schema designs beyond the text-and-API model assumed here.
The open-source implementations described here are available for community contribution and extension. We hope this work contributes a practical and principled foundation for the runtime governance layer that autonomous AI systems increasingly require.