AI Agent Monitoring Tools: Comprehensive Guide
The tools and techniques for monitoring AI agents in production.
Monitoring AI agents is critical for maintaining quality, controlling costs, and ensuring security. This guide covers the best monitoring tools, what metrics to track, and how to set up effective observability.
Why AI Agent Monitoring Is Different
Traditional application monitoring tracks uptime, latency, and error rates. AI agent monitoring needs all that plus:
- Quality metrics β Is the agent giving good answers?
- Cost metrics β How much is each conversation costing?
- Safety metrics β Is the agent behaving safely?
- Tool metrics β Are the agent's tool calls working?
- User experience β Are users satisfied?
What to Monitor
Core Metrics Dashboard
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Agent Monitoring β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ€
β RESPONSE TIME β p50: 2.1s p95: 8.3s p99: 15sβ
β ERROR RATE β 2.3% (target: < 5%) β
β DAILY COST β β¬127.50 (budget: β¬200) β
β ACTIVE USERS β 342 today β
β SATISFACTION β 4.2/5 (β 0.1 from yesterday) β
β TOOL SUCCESS β 96.8% β
β ESCALATION RATE β 12% (target: < 20%) β
ββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
Top Monitoring Tools
1. LangSmith (by LangChain)
Best for: LangChain-based agents
import langsmith
# Enable tracing
langsmith.trace(
project="production-agent",
api_key="ls_xxx",
)
# Every LLM call, tool use, and chain is automatically traced
# View in LangSmith dashboard
Features:
- Full conversation traces
- Token usage per call
- Cost tracking
- Quality evaluation
- A/B testing
- Price: Free tier / β¬39+/month
2. Langfuse (Open Source)
Best for: Cost-conscious teams
from langfuse import Langfuse
langfuse = Langfuse(
public_key="pk-xxx",
secret_key="sk-xxx",
host="https://cloud.langfuse.com",
)
# Trace agent execution
@langfuse.observe()
async def process_request(user_message):
span = langfuse.span(name="llm_call")
response = await llm.complete(user_message)
span.end()
langfuse.score(
trace_id=trace.id,
name="user_satisfaction",
value=response.feedback,
)
Features:
- Open source (self-hostable)
- Full trace visibility
- Cost analytics
- Prompt management
- Price: Free (self-hosted) / Cloud plans
3. Phoenix (by Arize)
Best for: ML teams transitioning to LLMs
import phoenix as px
from phoenix.trace.langchain import LangChainInstrumentor
# Start Phoenix
px.launch_app()
# Auto-instrument LangChain
LangChainInstrumentor().instrument()
# View traces in Phoenix UI at localhost:6006
Features:
- LLM traces
- Embedding analysis
- Evaluation
- Price: Free (open source) / Enterprise
4. Helicone
Best for: OpenAI-focused monitoring
import helicone
# Proxy OpenAI calls through Helicone
helicone.openai_proxy(api_key="helicone-key")
# All OpenAI calls are now logged and monitored
response = openai.chat.completions.create(...)
Features:
- Drop-in OpenAI proxy
- Request logging
- Cost tracking
- Rate limiting
- Caching
- Price: Free / β¬29+/month
5. Portkey
Best for: Multi-provider monitoring
from portkey import Portkey
portkey = Portkey(
api_key="pk-xxx",
)
# Works across multiple LLM providers
response = portkey.chat.completions.create(
model="claude-sonnet-4",
messages=[...],
)
Features:
- Multi-provider gateway
- Fallback management
- Caching
- Load balancing
- Price: β¬35+/month
Building Custom Monitoring
Token and Cost Tracking
class TokenMonitor:
PRICING = {
"gpt-4o": {"input": 2.50, "output": 10.00}, # per 1M tokens
"gpt-4o-mini": {"input": 0.075, "output": 0.30},
"claude-sonnet-4": {"input": 3.00, "output": 15.00},
"claude-haiku-3.5": {"input": 0.25, "output": 1.25},
}
async def track(self, model, input_tokens, output_tokens, user_id):
cost = self.calculate_cost(model, input_tokens, output_tokens)
await self.metrics.record(
model=model,
input_tokens=input_tokens,
output_tokens=output_tokens,
cost=cost,
user_id=user_id,
timestamp=datetime.utcnow(),
)
# Check budget
daily_total = await self.metrics.get_daily_total()
if daily_total > self.daily_budget * 0.8:
await self.alert_team(f"Budget alert: β¬{daily_total:.2f}/{self.daily_budget}")
def calculate_cost(self, model, input_tokens, output_tokens):
pricing = self.PRICING.get(model, {"input": 1.0, "output": 2.0})
return (
input_tokens / 1_000_000 * pricing["input"] +
output_tokens / 1_000_000 * pricing["output"]
)
Quality Monitoring
class QualityMonitor:
async def track_response(self, conversation_id, response):
# Automated quality checks
checks = {
"relevance": await self.check_relevance(response),
"factuality": await self.check_facts(response),
"safety": await self.check_safety(response),
"tone": await self.check_tone(response),
}
await self.db.insert("quality_metrics", {
"conversation_id": conversation_id,
"response": response,
"checks": checks,
"overall_score": sum(checks.values()) / len(checks),
})
async def check_relevance(self, response):
"""Check if response is relevant to the question."""
# Use a smaller model to evaluate
score = await evaluator_llm.evaluate(
f"Rate relevance 0-1: Question: {question}\nAnswer: {response}"
)
return float(score)
Tool Call Monitoring
class ToolCallMonitor:
async def record(self, tool_name, params, result, duration):
await self.db.insert("tool_calls", {
"tool": tool_name,
"params": sanitize(params), # Remove sensitive data
"success": result.get("success", True),
"duration_ms": duration,
"timestamp": datetime.utcnow(),
})
async def get_health(self):
"""Get health metrics for all tools."""
tools = await self.db.query("""
SELECT tool,
COUNT(*) as total,
SUM(CASE WHEN success THEN 1 ELSE 0 END) as success_count,
AVG(duration_ms) as avg_duration
FROM tool_calls
WHERE timestamp > NOW() - INTERVAL '24 hours'
GROUP BY tool
""")
return {
t.tool: {
"success_rate": t.success_count / t.total,
"avg_duration": t.avg_duration,
"calls": t.total,
}
for t in tools
}
Alerting Setup
Alert Rules
alerts:
- name: high_error_rate
condition: "error_rate > 5% over 5 minutes"
severity: warning
notify: [slack, email]
- name: critical_error_rate
condition: "error_rate > 15% over 2 minutes"
severity: critical
notify: [slack, email, pagerduty]
- name: budget_threshold
condition: "daily_cost > 80% of budget"
severity: warning
notify: [slack]
- name: budget_exceeded
condition: "daily_cost > 100% of budget"
severity: critical
action: disable_agent
notify: [slack, email]
- name: latency_spike
condition: "p95_latency > 15s over 10 minutes"
severity: warning
notify: [slack]
- name: low_satisfaction
condition: "avg_satisfaction < 3.5 over 1 hour"
severity: warning
notify: [slack]
- name: injection_detected
condition: "prompt_injection_count > 10 in 1 hour"
severity: critical
notify: [slack, pagerduty]
Log Management
Structured Logging
import structlog
logger = structlog.get_logger()
async def process_message(user_id, message):
logger.info(
"message_received",
user_id=user_id,
message_length=len(message),
session_id=session.id,
)
try:
response = await agent.process(message)
logger.info(
"response_generated",
user_id=user_id,
response_length=len(response.content),
tokens_used=response.token_usage,
cost_eur=response.cost,
tools_used=response.tool_calls,
duration_ms=response.duration_ms,
)
except Exception as e:
logger.error(
"processing_failed",
user_id=user_id,
error=str(e),
error_type=type(e).__name__,
)
raise
Dashboards
Key Dashboard Panels
Request Overview
- Requests per minute/hour/day
- Active users
- Response time distribution
Cost Analysis
- Daily/monthly spend
- Cost per conversation
- Cost by model
- Budget utilization
Quality Metrics
- User satisfaction trend
- Feedback distribution
- Escalation rate
- Hallucination reports
Tool Health
- Tool call success rates
- Tool latency
- Most/least used tools
Security
- Injection attempts
- Rate limit hits
- Unusual activity patterns
Conclusion
Effective monitoring is the difference between an AI agent that degrades silently and one that stays healthy. By tracking the right metrics, setting up alerts, and using the right tools, you can maintain quality and control costs.
Start with basic monitoring (cost + errors + latency), then layer in quality and security monitoring as you mature.
Learn More
- AI Agent Observability
- AI Agent Logging Best Practices
- AI Agent Debugging Tools
- AI Agent Deployment Best Practices
Explore monitoring tools on SkillExchange.