Overview
Monitoring is essential for running production multi-agent systems. This guide covers how to monitor agent performance, track metrics, implement logging, and gain full observability into your Swarms deployment.Built-in observability
Swarms gives you three signals without any setup:Tracing
OpenTelemetry spans for every agent and swarm run, on by default
Token usage
agent.usage and router.usage totals reported by the providerLog files
Console output plus files under
{WORKSPACE_DIR}/logs/agent.usage is a running total for the instance, with the keys input_tokens, output_tokens, cached_tokens, reasoning_tokens, and total_tokens.
Logging Architecture
Loguru Integration
Swarms uses Loguru. On import it adds a console sink and two file sinks under{WORKSPACE_DIR}/logs/: a combined swarms_YYYY-MM-DD.log, rotated daily and kept for 10 days, and one <module>.log per Swarms module that logs, such as agent.log or graph_workflow.log. Errors from standard-library loggers go to {WORKSPACE_DIR}/error.txt.
To replace the defaults with your own configuration, remove the existing sinks first. This also removes the workspace log files:
Multi-Level Logging
Configure different log levels for different outputs:Contextual Logging
Add context to logs for better traceability:Agent-Level Monitoring
Built-in Verbose Mode
Custom Monitoring Wrapper
Performance Metrics
Response Time Tracking
Throughput Monitoring
Error Tracking
Error Rate Monitoring
Health Checks
Agent Health Check
System Health Check
Alerting
Simple Alert System
Best Practices
1. Use Structured Logging
2. Log at Appropriate Levels
- DEBUG: Detailed diagnostic information
- INFO: General informational messages
- WARNING: Warning messages for recoverable issues
- ERROR: Error messages for failures
- CRITICAL: Critical errors requiring immediate attention
3. Include Context
4. Monitor Key Metrics
- Response time (mean, median, p95, p99)
- Throughput (requests per second/minute)
- Error rate, including
AgentLLMErrorraised once retries and fallback models are exhausted - Token usage per request, from
agent.usage - Resource usage (CPU, memory)
5. Set Up Alerts
- High error rates
- Slow response times
- Resource exhaustion
- Queue backlogs