Skip to main content

Governance-first observability for AI agents -- real-time metrics, anomaly detection, kill switches, compliance export.

License PyPI Docs Follow @CohorteAI

What It Does

Record every agent event. Compute real-time metrics over rolling windows. Detect anomalies via z-score baselines. Kill misbehaving agents instantly. Export compliance reports. All in-process, no external services, ~0.1ms per event.

This is not LangSmith, Langfuse, or Arize. Those are tracing platforms that collect data. This library collects data and acts on it -- anomaly detection triggers alerts, kill switches stop agents, compliance export generates audit reports. Governance, not just observation.

  • Event collection -- record agent actions, guardrail triggers, denials, approvals, costs, errors
  • Real-time metrics -- event count, denial rate, cost/minute, average latency over configurable rolling windows
  • Statistical baselines -- Welford's online algorithm for running mean and stddev, z-score anomaly detection
  • Kill switches -- instant agent/session/global kill, automatic kill policies on metric thresholds, persistence across restarts
  • Anomaly detection -- z-score rules with configurable thresholds, cooldown periods, wildcard agent matching
  • Compliance export -- SOC 2, GDPR, JSON reports with filtering by agent, time range, event type
  • Alert channels -- console, JSONL file, webhook (Slack, PagerDuty, OpsGenie)
  • OpenTelemetry -- optional export to any OTel-compatible backend
  • Guardrails adapter -- auto-record every theaios-guardrails decision

Quick Start

pip install theaios-agent-monitor

1. Write a config:

# monitor.yaml
version: "1.0"
metadata:
  name: my-monitor
  description: Production agent monitoring

metrics:
  default_window_seconds: 300

kill_switch:
  enabled: true
  policies:
    - name: auto-kill-on-high-cost
      metric: cost_per_minute
      operator: ">"
      threshold: 5.0
      action: kill_agent
      severity: critical

alerts:
  channels:
    - type: console

2. Use it:

import time
from theaios.agent_monitor import Monitor, load_config, AgentEvent

monitor = Monitor(load_config("monitor.yaml"))

# Record events
monitor.record(AgentEvent(
    timestamp=time.time(),
    event_type="action",
    agent="sales-agent",
    cost_usd=0.007,
    latency_ms=350.0,
    data={"model": "gpt-4"},
))

# View metrics
snap = monitor.get_metrics("sales-agent")
print(f"Events: {snap.event_count}")
print(f"Cost/min: ${snap.cost_per_minute:.4f}")
print(f"Denial rate: {snap.denial_rate:.1%}")

# Kill an agent
monitor.kill_agent("sales-agent", reason="Cost spike detected")

Events tell the monitor what's happening. Each event has an event_type, an agent, a timestamp, and optional fields for cost, latency, session, and arbitrary data:

import time

# Action event with cost and latency
monitor.record(AgentEvent(
    timestamp=time.time(), event_type="action", agent="my-agent",
    cost_usd=0.007, latency_ms=350.0,
    data={"model": "gpt-4"},
))

# Denial (guardrail blocked the request — feeds denial_rate metric)
monitor.record(AgentEvent(
    timestamp=time.time(), event_type="denial", agent="my-agent",
    data={"rule": "block-injection", "severity": "critical"},
))

# Guardrail trigger (non-denial, e.g., redact or log)
monitor.record(AgentEvent(
    timestamp=time.time(), event_type="guardrail_trigger", agent="my-agent",
    data={"rule": "redact-pii", "outcome": "redact"},
))

# Error
monitor.record(AgentEvent(
    timestamp=time.time(), event_type="error", agent="my-agent",
    data={"error_type": "TimeoutError", "message": "LLM call timed out"},
))

3. CLI:

agent-monitor -c monitor.yaml validate
agent-monitor -c monitor.yaml inspect
agent-monitor -c monitor.yaml status --agent sales-agent
agent-monitor -c monitor.yaml events --agent sales-agent --type action
agent-monitor -c monitor.yaml kill sales-agent --reason "Cost spike"
agent-monitor -c monitor.yaml revive sales-agent
agent-monitor -c monitor.yaml export --format soc2

Why This Library?

Every agentic system needs monitoring. The options today:

Approach Problem
LangSmith / Langfuse Tracing only -- no kill switches, no anomaly detection, no compliance export
Arize / Weights & Biases ML-focused, not agent-governance-focused, expensive at scale
Datadog / Grafana Generic APM -- doesn't understand denial rates, guardrail decisions, or agent costs
Build your own Months of engineering, no standard format, no z-score baselines

theaios-agent-monitor is governance-first (kill switches and compliance, not just dashboards), statistical (z-score anomaly detection, not threshold-only), instant (in-process, ~0.1ms/event, no external services), and declarative (YAML configs that ops teams can read).

Source Types

Source What it provides
Events Append-only log of every agent action
Metrics Rolling window: event_count, denial_rate, cost_per_minute, avg_latency_ms
Baselines Welford's algorithm: running mean, stddev, z-score
Anomalies Z-score threshold alerts with cooldown
Kill switches Agent/session/global kill with auto-policies
Compliance SOC 2, GDPR, JSON export

Documentation

Full documentation at cohorte-ai.github.io/agent-monitor -- including the config syntax reference, events, metrics & baselines, kill switches, compliance, and integration guide.

Part of the theaios Ecosystem

theaios-agent-monitor is one of the theaios platform components. It works standalone or alongside:

License

Apache 2.0 -- see LICENSE.

Metadata

Release files for theaios-agent-monitor 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for theaios-agent-monitor 0.1.2
File Size Uploaded
theaios_agent_monitor-0.1.2.tar.gz 89.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for theaios-agent-monitor 0.1.2
File Interpreter ABI Platform
theaios_agent_monitor-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 132.7 kB

Release files / theaios_agent_monitor-0.1.2.tar.gz

Download URL theaios_agent_monitor-0.1.2.tar.gz
Size 89.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4ea49b310570fb311e6d8e3dff67cb2f50aa8418c451757561004227d7946ca9
BLAKE2b-256 checksum
How to use checksums
ee4aa2ecaed5743d83de175499e13adb7e6642aee4aa72ab26372e2b25f0cf15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / theaios_agent_monitor-0.1.2-py3-none-any.whl

Download URL theaios_agent_monitor-0.1.2-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5a6f985e4af8e670142b6731e63205de25cc6303522a56cf5eeaa0326168d76
BLAKE2b-256 checksum
How to use checksums
723c5783d7abc17aab79b0180cf22ae0fbc66502612a4a9c05747cc93090540b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page