Observability¶
G6 includes a built-in observability stack powered by Prometheus and Grafana. The Recursive Architect engine exports real-time metrics on task execution, token usage, tool calls, self-healing, cost tracking, and constraint satisfaction — giving operators full visibility into what the AI is doing, how much it costs, and whether safety bounds are holding.
Architecture¶
┌──────────────────────┐
│ Recursive Architect │
│ (ArchitectMetrics) │
│ port 9092 │
└──────────┬───────────┘
│ scrape /metrics
▼
┌──────────────────────┐ ┌──────────────────────┐
│ Prometheus │◄────│ PushGateway │
│ port 9090 │ │ port 9091 │
└──────────┬───────────┘ └──────────▲────────────┘
│ query │ push
▼ │
┌──────────────────────┐ ┌──────────┴────────────┐
│ Grafana │ │ AlertDispatcher │
│ port 3000 │ │ (CI/CD alerts) │
│ dashboards + alerts │ └───────────────────────┘
└──────────────────────┘
Pull model: Prometheus scrapes the ArchitectMetrics HTTP server every 5 seconds. Metrics are registered with a per-instance CollectorRegistry so multiple architect runs don't collide.
Push model: The CI/CD AlertDispatcher pushes deployment event counters to PushGateway for short-lived jobs (deploy scripts, health checks) that exit before Prometheus can scrape them.
Metrics Reference¶
Counters (monotonically increasing)¶
| Metric | Labels | Description |
|---|---|---|
architect_tasks_total | run_id, status | Branch tasks by completion status |
architect_checkpoints_total | run_id | Checkpoint evaluations performed |
architect_guardrail_violations_total | run_id, name | Safety guardrail violations detected |
architect_hitl_tasks_total | run_id | Human-in-the-loop tasks emitted |
architect_crashes_total | run_id | Execution crashes |
architect_tokens_total | run_id, token_type | LLM tokens consumed (prompt, completion, total) |
architect_tool_calls_total | run_id, component | Tool/component invocations |
architect_self_healing_total | run_id, outcome | Self-healing attempts (attempted, succeeded) |
g6_deploy_alert_total | severity, source | Deployment alerts (pushed via PushGateway) |
Gauges (current value)¶
| Metric | Labels | Description |
|---|---|---|
architect_hitl_pending | run_id | Currently pending HITL tasks |
architect_branches_active | run_id | Currently active execution branches |
architect_subgoals_complete | run_id | Completed subgoals |
architect_subgoals_total | run_id | Total subgoals |
architect_constraint_satisfaction_pct | run_id | Constraint satisfaction percentage (0-100) |
architect_cost_usd_gauge | run_id | Accumulated cost in USD |
Histograms¶
| Metric | Labels | Description |
|---|---|---|
architect_task_duration_seconds | run_id, component | Branch execution duration (with bucket quantiles) |
Pre-built Dashboard¶
The g6_architect.json dashboard is auto-provisioned into Grafana with 10 panels:
| Panel | Type | What it shows |
|---|---|---|
| Subgoal Progress | Stat | Fraction of subgoals completed (0-100%) |
| Total Tokens | Stat | Cumulative LLM token count |
| Token Rate (5m) | Time series | Prompt and total tokens per second over 5-minute windows |
| Tool Calls | Stat | Total tool/component invocations |
| Self-Healing Rate | Gauge | Success rate of self-healing attempts |
| Cost (USD) | Stat | Accumulated LLM cost with color thresholds |
| Constraint Satisfaction | Gauge | Current constraint satisfaction percentage |
| HITL Queue Depth | Gauge | Pending human-in-the-loop tasks |
| Branch Duration p95/p50 | Time series | 95th and 50th percentile execution durations |
| Crashes | Stat | Total crash count |
Agent Runtime Metrics¶
Separate from the architect engine, the agent runtime (agent_claude, agent_openai, agent_autogen, agent_smolagents, …) records per-backend reliability metrics in components/mvp/agent_runtime/metrics.py (MetricsCollector, a process-wide singleton via get_collector()).
Metric families¶
| Metric | Labels | Description |
|---|---|---|
agent_infer_total | agent, status | Inference calls by completion status |
agent_tokens_total | agent, direction | LLM tokens (in / out) |
agent_circuit_state | agent, backend | Circuit-breaker state (0=closed, 1=open, 2=half_open) |
agent_latency_p50_ms | agent, status | Median latency over the recent sample window |
agent_latency_p95_ms | agent, status | 95th-percentile latency over the recent sample window |
Latency percentiles are nearest-rank over a sliding window of the most recent 1024 samples per (agent, status) — bounded memory, percentiles over recent behaviour.
Exposure surfaces¶
-
Prometheus text — the agent metrics server (
mvp.agent_runtime.server) serves/metricsonAGENT_METRICS_PORT(default9090), started automatically byLifecycleMixin.start(). Scraped by theagent_runtimejob ininfra/prometheus.yml.Port 9090 collides with Prometheus
The default
9090is also Prometheus's conventional port. On a single host (or if Prometheus publishes host port 9090) setAGENT_METRICS_PORTto a free port (e.g.9093) and update theagent_runtimetarget ininfra/prometheus.ymlto match. -
REST JSON —
GET /observability/agent-metricsreturns the same data as JSON (bases/mvp/rest/routes/health.py, viaMetricsCollector.snapshot()) for the GUI and any non-Prometheus consumer. It reflects the in-process collector — agent activity in that API process. For cross-process aggregation and time-series, use Grafana (scrape the runtime endpoint). -
GUI — Settings → Monitoring renders the live snapshot (latency p50/p95 bars, inference counts, token throughput, circuit-breaker badges), polling
/observability/agent-metricsevery 5 s. SetNEXT_PUBLIC_G6_GRAFANA_URLto surface an "Open in Grafana" link.
Pre-built dashboard — g6_agent_runtime.json¶
Auto-provisioned into Grafana (4 panels):
| Panel | Type | What it shows |
|---|---|---|
| Agent Latency p50 / p95 | Time series | Per-(agent, status) p50 and p95 in ms |
| Inference Rate by Agent / Status | Time series | rate(agent_infer_total[5m]) |
| Token Throughput by Agent / Direction | Time series | rate(agent_tokens_total[5m]) |
| Circuit-Breaker State by Agent / Backend | Stat | agent_circuit_state mapped to closed/open/half_open |
Alerts¶
Three deployment alerts are provisioned in Grafana via deploy-alerts.yml:
| Alert | Condition | Severity |
|---|---|---|
| DeployRollback | g6_deploy_alert_total{severity="critical",source="rollback"} > 0 | Critical |
| HealthCheckFailing | g6_deploy_alert_total{source="health_check"} > 3 within 1 min | Warning |
| HighDeployFailureRate | rate(g6_deploy_alert_total{severity="critical"}[5m]) > 0.1 sustained 5 min | Critical |
Configuration¶
| Setting | Default | Description |
|---|---|---|
| Metrics server port | 9092 | Set via RecursiveArchitectBlock.metrics_port |
| Prometheus scrape interval | 5s | Configured in infra/prometheus.yml |
| Grafana admin password | Required | Set GRAFANA_ADMIN_PASSWORD env var (prod) or defaults to admin (dev) |
| PushGateway URL | http://pushgateway:9091 | AlertDispatcher.pushgateway_url |
Deployment modes¶
- Dev (
docker-compose.yml): Prometheus onlocalhost:9090, Grafana onlocalhost:3000 - Prod (
docker-compose.prod.yml): Prometheus internal only (no exposed port), Grafana on port 3000 - Blue-green (
docker-compose.base.yml): Shared Prometheus + Grafana across blue/green slots
How it Works¶
The ArchitectMetrics class (components/mvp/recursive_architect/metrics.py) wraps prometheus_client counters, gauges, and histograms. Every recording method updates both:
- In-memory counters — always available, used by the TUI dashboard
- Prometheus collectors — only if
prometheus_clientis installed
If prometheus_client is not installed, the class silently falls back to in-memory counters only. The TUI and API continue to work — you just lose the Prometheus/Grafana pipeline.
FAQ¶
Do I need Prometheus and Grafana to run G6?
No. ArchitectMetrics falls back to in-memory counters when prometheus_client is not installed. The CLI/TUI displays metrics directly from these counters. Prometheus and Grafana add historical time-series storage and visual dashboards but are not required for operation.
Can I use a different monitoring backend?
Yes. Metrics are exposed as standard Prometheus exposition format on /metrics (port 9092). Any Prometheus-compatible scraper works — Datadog Agent, New Relic, Victoria Metrics, Thanos, or Grafana Alloy.
What is the difference between pushed and scraped metrics?
Scraped metrics (pull model) are used by ArchitectMetrics for long-running architect sessions. Prometheus fetches them every 5 seconds. Pushed metrics are used by AlertDispatcher for short-lived CI/CD jobs (deploy scripts, health checks) that may exit before Prometheus can scrape them. PushGateway acts as a buffer.
How do I add custom metrics?
- Add a new Counter/Gauge/Histogram in
ArchitectMetrics._init_prometheus() - Add a corresponding key to
self._countersin__init__ - Write a
record_*()method that updates both the in-memory counter and the Prometheus collector - The metric will automatically appear in Prometheus and can be added to the Grafana dashboard
What dashboard panels come pre-built?
Ten panels covering subgoal progress, token usage and rate, tool calls, self-healing success rate, cost tracking, constraint satisfaction, HITL queue depth, branch execution duration percentiles, and crash count. See the Pre-built Dashboard section above.