Triage, classify, prioritise, and draft responses to emails automatically with LLM agents.
Email and Communication Automation
import anthropic, smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
client = anthropic.Anthropic()
def triage_email(subject: str, body: str) -> dict:
"""Classify and draft response for incoming email."""
resp = client.messages.create(
model="claude-opus-4-5", max_tokens=800,
system="You are an email assistant. Respond with JSON only.",
messages=[{"role":"user","content":f"""Email:
Subject: {subject}
Body: {body}
Return JSON:
{{
"category": "support|billing|sales|spam|other",
"priority": "high|medium|low",
"sentiment": "positive|neutral|negative",
"needs_human": true/false,
"draft_response": "suggested reply if simple"
}}"""}]
)
return json.loads(resp.content[0].text)
def smart_reply(emails: list[dict], context: str) -> str:
"""Draft email reply using company context."""
resp = client.messages.create(
model="claude-opus-4-5", max_tokens=500,
system=f"Company context: {context}. Write professional email replies.",
messages=[{"role":"user","content":f"Draft reply to: {emails[-1]}"}]
)
return resp.content[0].text