title | publishedAt | updatedAt | summary | kind |
---|---|---|---|---|
Workers |
2024-11-10 |
2025-02-17 |
Standalone task executors that perform single, focused operations using plugins. |
detailed |
Workers are specialized task executors that follow the single responsibility principle. Each worker is designed to do one thing and do it well, making them reliable, maintainable, and easily testable.
Unlike workflows that chain multiple steps together, workers are focused on a single, specific task. This makes them:
- More reliable (fewer points of failure)
- Easier to test and debug
- More maintainable over time
- Reusable across different workflows
-
Single Responsibility
- Each worker does exactly one thing
- Clear, focused purpose
- No task overlap between workers
-
Independence
- Workers operate independently
- No direct dependencies on other workers
- Self-contained functionality
-
Reliability
- Focused scope means fewer failure points
- Easier to test and validate
- Clear success/failure conditions
-
Reusability
- Can be used in multiple workflows
- Consistent interface
- Well-defined inputs and outputs
Extracts feature information using Perplexity AI:
- Single focus: Feature extraction
- Uses official sources
- Saves raw responses for verification
from pynions.workers import PerplexityFeaturesWorker
async def analyze_features():
worker = PerplexityFeaturesWorker()
result = await worker.execute({"domain": "example.com"})
Advanced pricing data extraction using Perplexity AI's research capabilities:
- Direct URL Analysis: Finds and validates official pricing pages
- First-Party Data: Prioritizes data from official sources
- Cross-Reference: Validates with trusted third-party sources
- Structured Output: Clean, validated JSON with source tracking
from pynions.workers import PerplexityPricingWorker
async def analyze_pricing():
worker = PerplexityPricingWorker()
result = await worker.execute({"domain": "example.com"})
- Inherit from base Worker class
from pynions import Worker
class CustomWorker(Worker):
"""Worker with a single, focused purpose"""
def __init__(self):
# Initialize required plugin
self.plugin = Plugin()
async def execute(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
# Implement single focused task
pass
-
Single Purpose
- One clear task per worker
- Avoid feature creep
- Clear documentation of purpose
-
Error Handling
- Handle errors specific to the task
- Clear error messages
- Proper error propagation
-
Data Management
- Save raw responses
- Clear data structure
- Proper file organization
-
Testing
- Test single responsibility
- Verify error cases
- Validate output format
- Scope creep (trying to do too much)
- Unclear responsibility boundaries
- Insufficient error handling
- Poor data organization
Need help? Check our debugging guide for solutions.