Runtime Events
Overview
The AG-Kit Runtime Event System provides a powerful, optimized way to handle real-time events during agent execution. It supports event batching, async processing, and performance monitoring.Event Types
Core Events
run_started- Agent execution beginsrun_finished- Agent execution completes successfullyrun_failed- Agent execution fails with errortext_message_start- Text message generation beginstext_message_content- Text message content is generatedtext_message_end- Text message generation completestool_call_start- Tool execution beginstool_call_end- Tool execution completestool_call_result- Tool execution result is availablestate_update- Agent state is updatedapproval_required- Human approval is requiredapproval_received- Human approval is receivederror- An error occurs during execution
Event Handling
Basic Event Listening
Optimized Event System
Event Data Structure
Base Event
Specific Event Types
Performance Optimization
Event Batching
The optimized event system automatically batches events for better performance:Async Processing
Enable async event processing for non-blocking operations:Best Practices
- Event Cleanup: Remove event listeners when no longer needed
- Error Handling: Always handle error events appropriately
- Performance: Use optimized event system for high-throughput scenarios
- Monitoring: Monitor event system performance metrics
- Batching: Configure appropriate batch sizes for your use case
Related Documentation
- Runtime Overview - Runtime system overview
- Runtime API - Complete API reference
- Runtime Examples - Code examples and patterns