AI Agent SLA Design: Key Metrics for Service Quality
AI Agent SLA Design: Key Metrics for Service Quality
📖 Keep reading
| P50 | P95 | P99 | ||
|---|---|---|---|---|
| >99.5% | >98% | >95% | ||
| >90% | >85% | >80% | ||
| 100% | 99.9% | 99.5% |
import time
import json
from datetime import datetime
from collections import deque
class SLAMonitor:
def __init__(self, window_minutes=60):
self.window = window_minutes * 60
self.latencies = deque()
self.success_count = 0
self.total_count = 0
self.errors = {}
def record(self, latency_ms: float, success: bool, error_type: str = None):
now = time.time()
self.latencies.append((now, latency_ms))
self.total_count += 1
if success:
self.success_count += 1
else:
self.errors[error_type] = self.errors.get(error_type, 0) + 1
while self.latencies and now - self.latencies[0][0] > self.window:
self.latencies.popleft()
def report(self) -> dict:
latencies = [l[1] for _, l in self.latencies]
latencies.sort()
n = len(latencies)
success_rate = self.success_count / max(self.total_count, 1)
p50 = latencies[int(n * 0.5)] if n else 0
p95 = latencies[int(n * 0.95)] if n else 0
p99 = latencies[int(n * 0.99)] if n else 0
return {
"timestamp": datetime.now().isoformat(),
"total_requests": self.total_count,
"success_rate": round(success_rate * 100, 2),
"latency_ms": {"p50": p50, "p95": p95, "p99": p99},
"error_breakdown": dict(sorted(self.errors.items(), key=lambda x: -x[1])[:5])
}
monitor = SLAMonitor(window_minutes=60)
def agent_call(user_input: str) -> str:
start = time.time()
try:
result = agent.invoke(user_input)
elapsed = (time.time() - start) * 1000
monitor.record(elapsed, success=True)
return result
except Exception as e:
elapsed = (time.time() - start) * 1000
monitor.record(elapsed, success=False, error_type=type(e).__name__)
raise
print(json.dumps(monitor.report(), ensure_ascii=False, indent=2))
Related Articles
2026-08-14
ComfyUI Workflows 2026: How to Load, Edit and Share Node Graphs
2026-07-16
AutoGen Multi Agent Tutorial 2026
2026-08-01
Agentic RAG Example 2026: 5 Working Patterns Beyond Simple Retrieval
2026-08-31
Spent a week doing dirty work with Doubao Seed Evolving: A hands-on report from a veteran Agent user
2026-07-16
AI Agent Docker Deployment 2026
2026-07-17
AI Agent Changelog Automation 2026
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.