quantum-ai-v2/email_writer/processor.py
Claude 8e075454d4 Add comprehensive agent creation system with template prototype
- Create AGENT_CREATION_GUIDE.md with complete step-by-step instructions
- Add agent_template_prototype.html with full CSS framework and JavaScript utilities
- Implement Email Writer agent as demonstration of template system
- Update CLAUDE.md with agent creation workflow and template guidance
- Include Django patterns, form handling, status polling, and marketplace integration
- Provide reusable components: wallet card, processing status, quick access panel
- Ensure responsive design, accessibility, and consistent user experience

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-25 02:34:46 +05:30

79 lines
2.9 KiB
Python

import json
from agent_base.processors import BaseAgentProcessor
from .models import EmailWriterRequest
class EmailWriterProcessor(BaseAgentProcessor):
"""Email Writer agent processor"""
model_class = EmailWriterRequest
agent_name = "Email Writer"
cost = 3.00 # AED per request
def prepare_webhook_data(self, request_obj):
"""Prepare data for webhook processing"""
return {
'email_type': request_obj.email_type,
'recipient': request_obj.recipient,
'subject': request_obj.subject,
'main_message': request_obj.main_message,
'tone': request_obj.tone,
'length': request_obj.length,
}
def process_webhook_response(self, request_obj, webhook_response):
"""Process webhook response and update request object"""
try:
if isinstance(webhook_response, str):
response_data = json.loads(webhook_response)
else:
response_data = webhook_response
# Extract email content from response
email_content = ""
# Try different possible response formats
if 'email_content' in response_data:
email_content = response_data['email_content']
elif 'content' in response_data:
email_content = response_data['content']
elif 'output' in response_data:
email_content = response_data['output']
elif 'generated_email' in response_data:
email_content = response_data['generated_email']
elif isinstance(response_data, str):
email_content = response_data
else:
# If no specific field found, try to extract text
email_content = str(response_data)
# Update request object
request_obj.email_content = email_content
request_obj.save()
return {
'success': True,
'email_content': email_content,
'status': 'completed'
}
except Exception as e:
return {
'success': False,
'error': f"Failed to process email generation: {str(e)}",
'status': 'failed'
}
def get_result_summary(self, request_obj):
"""Get a summary of the results for display"""
if request_obj.email_content:
return {
'email_type': request_obj.get_email_type_display(),
'recipient': request_obj.recipient,
'tone': request_obj.get_tone_display(),
'length': request_obj.get_length_display(),
'email_content': request_obj.email_content,
'has_subject': bool(request_obj.subject),
'subject': request_obj.subject
}
return None