CoolFace
Apppublic

jmc310/deep_research

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
email_agent.py30 linesDownload Raw Back to root
1import os
2from typing import Dict
3
4import sendgrid
5from sendgrid.helpers.mail import Email, Mail, Content, To
6from agents import Agent, function_tool
7
8@function_tool
9def send_email(subject: str, html_body: str) -> Dict[str, str]:
10    """ Send an email with the given subject and HTML body """
11    sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
12    from_email = Email("jay@staffingengine.ai") # put your verified sender here
13    to_email = To("jmc310@gmail.com") # put your recipient here
14    content = Content("text/html", html_body)
15    mail = Mail(from_email, to_email, subject, content).get()
16    response = sg.client.mail.send.post(request_body=mail)
17    print("Email response", response.status_code)
18    return {"status": "success"}
19
20INSTRUCTIONS = """You are able to send a nicely formatted HTML email based on a detailed report.
21You will be provided with a detailed report. You should use your tool to send one email, providing the 
22report converted into clean, well presented HTML with an appropriate subject line."""
23
24email_agent = Agent(
25    name="Email agent",
26    instructions=INSTRUCTIONS,
27    tools=[send_email],
28    model="gpt-4o-mini",
29)
30