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.3

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.3
File Size Uploaded Provenance Actions
theaios_agent_monitor-0.1.3.tar.gz 87.1 kB Without provenance Details for theaios_agent_monitor-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 125.9 kB

Release files / theaios_agent_monitor-0.1.3.tar.gz

Download URL theaios_agent_monitor-0.1.3.tar.gz
Size 87.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fff06d0bfd007fac7f907854f3350c11ddc6eecbcc067b0417847fabf2036a1c
BLAKE2b-256 checksum
How to use checksums
dd3acec8de7b6def50a9bd0d79a18a83b22bf07fbfe0eada102eb8d2a38f0510
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL theaios_agent_monitor-0.1.3-py3-none-any.whl
Size 38.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
271b13793e53b904901f75d687e0215e2462b4f5eff30a6678fac5f833b5ecd1
BLAKE2b-256 checksum
How to use checksums
74e557d143ad861332216d2ca64c339fec61730128717cb9b8f178cd9fabe652
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for theaios-agent-monitor 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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