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:

shell
grep "$RUN_ID" logs/audit.jsonl

Record statuses

statusWritten when
spec_loadedA spec loaded and passed validation. Opens the run.
okAn allowed call ran. Includes latency_ms and a redacted result_preview.
deniedRules 1–8 refused the call, so it never ran.
interceptedRule 9 paused the call for approval.
denied_after_interceptThe approval callback returned False.
errorAn allowed call failed on the server side.
policy_evaluation_errorThe evaluator itself threw an error. The call was denied (fail closed).
response_pattern_detectedResponse 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.

FieldWhich records carry it
call_id, ts, statusAll records
run_idEvery record the wrapper writes. On spec_loaded, only when passed to the loader.
server, tool, argsTool-call records
matched_ruleEvery denial, intercept and waiver. Absent on a clean allow.
spec_hashEvery record a wrapped call writes, plus spec_loaded
latency_msok and error only
proposer_prompt_hashThe proposer's own records. Ties a generated spec to the version of the prompt that produced it.
Useful queries

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.

Limitation

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.

python
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:

ModeBehaviour
"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.
PatternTier
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 markerwarn
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 calls callback(server, tool, args, decision) -> bool synchronously. True lets the call run, and its ok record carries intercepted: true. False writes denied_after_intercept and raises PermissionError.
  • Without a callback, Aegis raises AegisApprovalRequired, which has everything you need for an approval flow outside the agent.
python
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 failsWhat happens
The policy evaluatorThe call is denied and a policy_evaluation_error record is written. Fails closed.
The OTLP collectorTool calls carry on. A line goes to stderr. JSONL is unaffected.
The control planeTool 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 AegisConfig per agent run. If no config is supplied, the run_id fallback 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_id to the loader.
  • Don't keep a reference to the unwrapped toolset. wrap_toolset modifies 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.