Skip to main content
This example demonstrates advanced SDK features for more complex automation scenarios. It analyzes notifications and takes actions based on their content.
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

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

Different tasks use different profiles optimized for their purpose:
Complex configuration is handled elegantly:
Captures execution for debugging:
  • Screenshots at each step
  • Agent decisions
  • Action results
Invaluable for understanding what went wrong!
Complex data structures with validation:

Customization Ideas

Trace Analysis

After running, examine the traces:
Each screenshot shows what the agent saw at that step, helping debug issues.

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

Next Steps

Core Concepts

Deep dive into profiles and builders

SDK Reference

Complete TaskRequestBuilder reference