This example demonstrates the powerful hook system integration in AtomicAgent, which leverages Instructor's hook system for comprehensive monitoring, error handling, and intelligent retry mechanisms.
- π Comprehensive Monitoring: Track all aspects of agent execution
- π‘οΈ Robust Error Handling: Graceful handling of validation and completion errors
- π Intelligent Retry Patterns: Implement smart retry logic based on error context
- π Performance Metrics: Monitor response times, success rates, and error patterns
- π§ Easy Debugging: Detailed error information and execution flow visibility
- β‘ Zero Overhead: Hooks only execute when registered and enabled
-
Clone the main Atomic Agents repository:
git clone https://github.com/eigenwise/atomic-agents
-
Navigate to the hooks-example directory:
cd atomic-agents/atomic-examples/hooks-example -
Install the dependencies using uv:
uv sync
-
Set up your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"
-
Run the example:
uv run python hooks_example/main.py
The example demonstrates several key hook system patterns:
- Simple parse error logging
- Completion monitoring and metrics collection
- Comprehensive validation error analysis
- Intelligent retry mechanisms with backoff strategies
- Error isolation to prevent hook failures from disrupting execution
- Response time tracking
- Success rate calculation
- Error pattern analysis
- Handling malformed responses
- Network timeouts and retry logic
- Model switching on repeated failures
This hook system implementation provides:
- Full Instructor Integration: All Instructor hook events are supported
- Backward Compatibility: Existing AtomicAgent code works unchanged
- Error Context: Rich error information for intelligent decision making
- Performance Insights: Detailed metrics for optimization
- Production Ready: Robust error handling suitable for production use
parse:error- Triggered on Pydantic validation failurescompletion:kwargs- Before API calls are madecompletion:response- After API responses are receivedcompletion:error- On API or network errors
This example demonstrates the complete resolution of GitHub issue #173, showing how the AtomicAgent hook system enables:
- β Parse error hooks triggering on validation failures
- β Comprehensive error context for retry mechanisms
- β Full Instructor hook event support
- β 100% backward compatibility
- β Robust error isolation
After running this example, you can:
- Experiment with different hook combinations
- Implement custom retry strategies
- Add your own monitoring and alerting logic
- Explore integration with observability platforms