This example is available on GitHub: smart_notification_assistant.py
What This Example Does
1
Checks notification panel
Opens notification panel and scans unread notifications
2
Categorizes by priority
Identifies high-priority notifications (messages, emails)
3
Extracts structured data
Returns typed data with app names, titles, and messages
4
Takes action
Creates a note summarizing the notifications
Advanced Features
Multiple Profiles
Uses different LLM configurations for different tasks
TaskRequestBuilder
Advanced task configuration with builder pattern
Trace Recording
Captures screenshots and execution steps
Exception Handling
Robust error handling with specific exceptions
Complete Code
smart_notification_assistant.py
Code Breakdown
1. Define Output Structures
Using enums for priority ensures the LLM returns only valid values.
2. Create Specialized Profiles
Analyzer profile: Uses powerful models for detailed inspection
Action profile: Optimized for quick actions
Action profile: Optimized for quick actions
3. Configure Agent with Multiple Profiles
4. Build Task with Advanced Options
5. Execute with Exception Handling
Running the Example
1
Set up API Keys
Ensure you have API keys for OpenAI, OpenRouter, and Google:
.env
2
Run the Script
3
View Traces
Check the traces directory for screenshots:
Expected Output
Key Concepts Demonstrated
Profile Switching
Profile Switching
Different tasks use different profiles optimized for their purpose:
Task Builder Pattern
Task Builder Pattern
Complex configuration is handled elegantly:
Trace Recording
Trace Recording
Captures execution for debugging:
- Screenshots at each step
- Agent decisions
- Action results
Nested Pydantic Models
Nested Pydantic Models
Complex data structures with validation:
Customization Ideas
- Different Actions
- Schedule-based
- Filter by App
Trace Analysis
After running, examine the traces:Best Practices Shown
Separate Profiles
Use different profiles for analysis vs. action
Descriptive Names
Name tasks for easier debugging
Enable Tracing
Always enable tracing during development
Specific Exceptions
Catch AgentError separately from general exceptions