Reference
Audit, OTLP & response inspection
What Aegis records, where the records go, and how to set up the controls that run alongside enforcement.
The audit log
Records are written as JSONL to logs/audit.jsonl. Each decision gets a record, and it is written before the outcome goes back to the agent. If otlp_endpoint is set, the same events are also exported as OTLP spans.
Every record the wrapper writes carries run_id, so a single search rebuilds a run's full sequence. Pass run_id=config.run_id to load_spec or propose_spec, and the opening spec_loaded record joins the run too:
grep "$RUN_ID" logs/audit.jsonl
Record statuses
| status | Written when |
|---|---|
spec_loaded | A spec loaded and passed validation. Opens the run. |
ok | An allowed call ran. Includes latency_ms and a redacted result_preview. |
denied | Rules 1–8 refused the call, so it never ran. |
intercepted | Rule 9 paused the call for approval. |
denied_after_intercept | The approval callback returned False. |
error | An allowed call failed on the server side. |
policy_evaluation_error | The evaluator itself threw an error. The call was denied (fail closed). |
response_pattern_detected | Response inspection matched a credential-shaped pattern. |
Fields
Fields differ by record type, on purpose. A denied call never ran, so it has no latency to report.
| Field | Which records carry it |
|---|---|
call_id, ts, status | All records |
run_id | Every record the wrapper writes. On spec_loaded, only when passed to the loader. |
server, tool, args | Tool-call records |
matched_rule | Every denial, intercept and waiver. Absent on a clean allow. |
spec_hash | Every record a wrapped call writes, plus spec_loaded |
latency_ms | ok and error only |
proposer_prompt_hash | The proposer's own records. Ties a generated spec to the version of the prompt that produced it. |
Records where matched_rule is not null: every denial and every waiver, and nothing else. Records with one spec_hash: the complete decision history of one policy, including the calls it allowed.
The log is append-only by convention, not cryptographically immutable. There's no hash chain or signature over the sequence yet; it's on the roadmap. If you need tamper-evidence, ship records to a WORM store or another append-only external system.
OTLP export
Point AegisConfig.otlp_endpoint at your collector: Datadog, Jaeger, Splunk, or anything that speaks OTLP.
config = AegisConfig(
sandbox_root=sandbox,
otlp_endpoint="https://otel-collector.internal:4318",
)Export uses BatchSpanProcessor, so the SDK handles retries and short outages. An unreachable collector never blocks or fails a tool call. It logs to stderr and carries on.
Response inspection
Aegis can scan tool responses for credential-shaped content before they reach the model. The scan uses fixed patterns, not a model. The mode is set with AegisConfig.response_inspection_mode:
| Mode | Behaviour |
|---|---|
"off" (default) | No scanning, no cost. |
"warn" | Matches are logged as response_pattern_detected with redacted previews. The response is still returned. |
"block" | A block-tier match raises PermissionError instead of returning the response. Warn-tier matches are logged only. |
| Pattern | Tier |
|---|---|
Private key headers (-----BEGIN … PRIVATE KEY-----) | block |
AWS access key IDs (AKIA + 16 characters) | block |
| Luhn-valid card numbers (13–19 digits) | block |
AWS-secret-shaped strings near an aws_secret marker | warn |
SSN-shaped values (NNN-NN-NNNN) | warn |
Response content is never modified. It's either returned or blocked. Separately, and in every mode including off, tool content is redacted in the audit fields, so the log never becomes the leak.
Handling intercepts
When a call matches an intercept rule, Aegis writes an intercepted record. What happens next depends on whether you've configured a callback:
- With
approval_callback, Aegis callscallback(server, tool, args, decision) -> boolsynchronously.Truelets the call run, and itsokrecord carriesintercepted: true.Falsewritesdenied_after_interceptand raisesPermissionError. - Without a callback, Aegis raises
AegisApprovalRequired, which has everything you need for an approval flow outside the agent.
from aegis import AegisApprovalRequired
try:
result = await agent.run(user_request)
except AegisApprovalRequired as exc:
# The call's arguments are on exc.call_args, NOT exc.args;
# Exception already owns .args for its string representation.
ticket = open_approval_ticket(exc.server, exc.tool, exc.call_args, exc.decision)Failure behaviour
| What fails | What happens |
|---|---|
| The policy evaluator | The call is denied and a policy_evaluation_error record is written. Fails closed. |
| The OTLP collector | Tool calls carry on. A line goes to stderr. JSONL is unaffected. |
| The control plane | Tool calls carry on. Records queue and catch up later, and gaps are counted. See fail-open. |
| The model API (e.g. HTTP 529) | Outside Aegis: it wraps tool calls, not model calls. Retry with backoff on your side. |
Production notes
- One
AegisConfigper agent run. If no config is supplied, therun_idfallback lasts for the whole process, so correlation would follow process lifetime instead of real run boundaries. - Create the config before loading the spec, so you can pass
run_id=config.run_idto the loader. - Don't keep a reference to the unwrapped toolset.
wrap_toolsetmodifies it in place, so the object you have is already governed. Make sure nothing else holds a copy taken before wrapping.
Source of truth: INTEGRATION.md on GitHub. If this page and the repository disagree, the repository wins — and please open an issue.