-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.py
More file actions
48 lines (39 loc) · 1.56 KB
/
entrypoint.py
File metadata and controls
48 lines (39 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from email_agent.agent import EmailDraftingAgent
import mlflow
import re
def compose_email(
bullets: str,
sender_name: str = "Your Name",
tone: str = "formal",
language: str = "en",
) -> dict:
"""
Entry point for AgentOS: wraps EmailDraftingAgent, prints and logs the composed email.
Supports multilingual outputs (English and Spanish). Normalizes greetings accordingly.
"""
agent = EmailDraftingAgent()
result = agent(
bullets=bullets, sender_name=sender_name, tone=tone, language=language,
)
# Extract subject and email body from the agent's output
subject = result.get("subject") if isinstance(result, dict) else None
email_body = result.get("email") if isinstance(result, dict) else None
# Multilingual greeting normalization
if email_body:
if language.lower().startswith("es"):
# Replace any leading English greeting with Spanish 'Hola'
email_body = re.sub(
r"^(?:¡?Hey!?|Hello)\s+([^\n,]+)", r"Hola \1", email_body
)
elif language.lower().startswith("en"):
# Replace any leading Spanish greeting with English 'Hello'
email_body = re.sub(
r"^(?:¡?Hey!?|Hola)\s+([^\n,]+)", r"Hello \1", email_body
)
# Combine subject and body into full email text
full_email = f"Subject: {subject}\n\n{email_body}"
# Print to console for CLI visibility
print(full_email)
# Log the email as a plain-text artifact in MLflow
mlflow.log_text(full_email, "email.txt")
return result