Overview
AgentCtrl provides a comprehensive event system for monitoring agent execution. This enables logging, telemetry, debugging, and custom integrations. You can either observe all events using a wiretap, or listen to specific event types for targeted monitoring. Key concepts:wiretap(): Observe ALL events with a single callbackonEvent(): Listen to specific event types (started, completed, text received, etc.)- Event types:
AgentExecutionStarted,AgentTextReceived,AgentToolUsed,AgentExecutionCompleted,AgentErrorOccurred - Real-time monitoring: Events fire during streaming execution
Example
Expected Output
Key Points
- Wiretap pattern: Observe all events with
wiretap()for comprehensive logging - Targeted listening: Use
onEvent()for specific event types when you only care about certain events - Real-time monitoring: Events fire as execution progresses, not after completion
- Rich metadata: Events include timestamps, model info, token usage, costs, and tool details
- Error handling: Listen to
AgentErrorOccurredfor exception handling - Multiple listeners: You can attach multiple callbacks to the same event type
- Use cases: Logging, telemetry, progress bars, debugging, analytics