Appearance
AgenTree Technical Monitoring
Introduction
The AgenTree monitoring system allows real-time tracking of agent execution, collection of metrics, tracing of key events, and customization of supervision according to the developer's needs. It relies on an event-driven architecture and modular strategies.
Monitoring Architecture
The core of the monitoring system is based on the AgentMonitor class, which observes agents via events:
- Monitored Events:
agentCreated,agentStarted,agentCompleted,agentErrorcontextLoaded,llmCall,toolCallschildCreated
- Configuration Options (
MonitoringOptions):logLevel :'silent' | 'basic' | 'detailed' | 'verbose'colors,timestamps,indentation: display customizationsaveToFile: log file path (optional)customLogger: custom logging function
The execution state is maintained in an agentTree structure (agent tree, depth, parentage).
Basic Usage
Detailed Monitoring (recommended)
ts
import { AgentMonitor } from 'src/monitoring/AgentMonitoring';
const monitor = new AgentMonitor({ logLevel: 'detailed' });
monitor.monitor(agent);
Simple Monitoring
ts
import { MonitoringPresets } from 'src/monitoring/presets';
MonitoringPresets.simple(agent);
Production Monitoring (minimal)
ts
MonitoringPresets.production(agent);
Advanced Strategies and Extension
Ready-to-use Presets
The MonitoringPresets class offers adapted strategies:
simple(agent): concise logs, suitable for quick debuggingdetailed(agent): hierarchical monitoring, colors, indentationproduction(agent): sober logs for productionwithMetrics(agent, cb?): metrics collection and callback (agents, LLM, tools, errors, total time)withLogging(agent, logFile?): saving to a filerealtime(agent, websocket?): real-time monitoring via WebSocketcustom(agent, options): selective event listening, custom callbacks
Filtering and Hierarchy
parentOnly,childrenOnly,byDepth,byParent: filtering of events according to depth or parentagehierarchical(agent): tree-like display with indentation
Extension
- Custom Logger: inject a function into
customLoggerto redirect logs (e.g., dashboard, remote storage) - Callbacks: attach functions to events to trigger actions or collect specific data
Best Practices
- Choose the appropriate preset:
detailedfor development,productionfor production,withMetricsfor analysis.
- Limit the log level in production (
logLevel: 'basic'or'silent') - Exploit the agent tree to visualize task decomposition
- Use callbacks to integrate monitoring with external tools (alerting, dashboards)
- Centralize logs via
saveToFileor a custom logger
Quick Reference
| Function / preset | Main usage |
|---|---|
AgentMonitor | Configurable, extensible monitoring |
simple | Concise logs, quick debugging |
detailed | Hierarchical, rich view |
production | Sober logs, suitable for production |
withMetrics | Metrics collection |
withLogging | Saving to a file |
realtime | Real-time monitoring (WebSocket) |
custom | Custom strategy, callbacks |
For more details, see the source code: src/monitoring/AgentMonitoring.tssrc/monitoring/presets.ts