deep_research / email_agent.py
mistliao's picture
Upload folder using huggingface_hub
2fe920d verified
import os
from typing import Dict
import requests
from agents import Agent, function_tool
@function_tool
def send_email(subject: str, html_body: str) -> Dict[str, str]:
"""Send out an email with the given subject and HTML body to all sales prospects using Resend"""
# Replace with your actual verified sender and target recipient
from_email = "mist.liao@resend.dev"
to_email = "chunyu.liao@gmail.com"
# Get the Resend API key from environment variable
RESEND_API_KEY = os.environ.get("RESEND_API_KEY")
headers = {
"Authorization": f"Bearer {RESEND_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"from": f"Mist Liao <{from_email}>",
"to": [to_email],
"subject": subject,
"html": html_body
}
response = requests.post("https://api.resend.com/emails", json=payload, headers=headers)
if response.status_code == 202:
return {"status": "success"}
else:
return {"status": "failure", "message": response.text}
INSTRUCTIONS = """You are able to send a nicely formatted HTML email based on a detailed report.
You will be provided with a detailed report. You should use your tool to send one email, providing the
report converted into clean, well presented HTML with an appropriate subject line."""
email_agent = Agent(
name="Email agent",
instructions=INSTRUCTIONS,
tools=[send_email],
model="gpt-4o-mini",
)