""" Pydantic models for the Email Assistant application. """ from typing import Optional, List, Dict, Any from pydantic import BaseModel, Field from enum import Enum class ToneType(str, Enum): FORMAL = "formal" CASUAL = "casual" ASSERTIVE = "assertive" class IntentType(str, Enum): REQUEST = "request" FOLLOW_UP = "follow_up" INTRODUCTION = "introduction" THANK_YOU = "thank_you" APOLOGY = "apology" INFORMATION = "information" MEETING = "meeting" COMPLAINT = "complaint" FEEDBACK = "feedback" GENERAL = "general" class EmailMetadata(BaseModel): """Metadata for email personalization.""" sender_name: Optional[str] = Field(default=None, description="Name of the sender") sender_company: Optional[str] = Field(default=None, description="Company of the sender") recipient_name: Optional[str] = Field(default=None, description="Name of the recipient") recipient_company: Optional[str] = Field(default=None, description="Company of the recipient") subject: Optional[str] = Field(default=None, description="Email subject line") additional_context: Optional[str] = Field(default=None, description="Any additional context") class EmailInput(BaseModel): """Input model for email generation.""" user_prompt: str = Field(..., description="The user's prompt describing what email to write") tone: ToneType = Field(default=ToneType.FORMAL, description="The tone of the email") intent: Optional[IntentType] = Field(default=None, description="The intent/purpose of the email") metadata: Optional[EmailMetadata] = Field(default=None, description="Optional metadata for personalization") class ParsedContext(BaseModel): """Parsed and normalized context from user input.""" original_prompt: str = Field(..., description="Original user prompt") normalized_prompt: str = Field(..., description="Cleaned and normalized prompt") key_points: List[str] = Field(default_factory=list, description="Key points extracted from the prompt") entities: Dict[str, str] = Field(default_factory=dict, description="Named entities extracted") urgency_level: str = Field(default="normal", description="Detected urgency level") class DetectedIntent(BaseModel): """Detected intent from the user prompt.""" primary_intent: IntentType = Field(..., description="Primary detected intent") confidence: float = Field(..., ge=0, le=1, description="Confidence score") secondary_intents: List[IntentType] = Field(default_factory=list, description="Secondary intents if any") reasoning: str = Field(default="", description="Reasoning for the classification") class EmailDraft(BaseModel): """Generated email draft.""" subject: str = Field(..., description="Email subject line") greeting: str = Field(..., description="Email greeting") body: str = Field(..., description="Email body content") closing: str = Field(..., description="Email closing") signature: str = Field(default="", description="Email signature") full_email: str = Field(default="", description="Complete formatted email") class ReviewResult(BaseModel): """Review feedback from the Review Agent.""" is_approved: bool = Field(..., description="Whether the draft passes review") tone_score: float = Field(..., ge=0, le=1, description="Tone appropriateness score") grammar_score: float = Field(..., ge=0, le=1, description="Grammar correctness score") clarity_score: float = Field(..., ge=0, le=1, description="Clarity and readability score") suggestions: List[str] = Field(default_factory=list, description="Improvement suggestions") issues: List[str] = Field(default_factory=list, description="Identified issues") class EmailState(BaseModel): """State object passed through the LangGraph workflow.""" # Input email_input: EmailInput # Processing stages parsed_context: Optional[ParsedContext] = None detected_intent: Optional[DetectedIntent] = None # Draft draft: Optional[EmailDraft] = None styled_draft: Optional[EmailDraft] = None # Review review_result: Optional[ReviewResult] = None # Control flow retry_count: int = Field(default=0, description="Number of retry attempts") max_retries: int = Field(default=2, description="Maximum retry attempts") current_agent: str = Field(default="", description="Currently executing agent") error_message: Optional[str] = Field(default=None, description="Error message if any") is_complete: bool = Field(default=False, description="Whether workflow is complete") class Config: use_enum_values = True