Spaces:
Sleeping
Sleeping
Download email_agent.py from Nagaraj91/Deep_Research_Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/Nagaraj91/Deep_Research_Agent/resolve/main/email_agent.py
- Command line
-
hf download hf://spaces/Nagaraj91/Deep_Research_Agent/email_agent.py
-
curl -L -o email_agent.py https://huggingface.co/spaces/Nagaraj91/Deep_Research_Agent/resolve/main/email_agent.py
1.27 kB
| from agents import Agent, ModelSettings, Tool, function_tool | |
| import sendgrid | |
| import os | |
| from sendgrid.helpers.mail import Mail, Email, To, Content | |
| from typing import Dict | |
| def send_email(subject: str, html_body: str) -> Dict[str, str]: | |
| """Send out an email with the given subject and HTML body""" | |
| sg = sendgrid.SendGridAPIClient(api_key=os.environ.get("SENDGRID_API_KEY")) | |
| from_email = Email("ed@edwarddonner.com") # Change this to your verified email | |
| to_email = To("ed.donner@gmail.com") # Change this to your email | |
| content = Content("text/html", html_body) | |
| mail = Mail(from_email, to_email, subject, content).get() | |
| sg.client.mail.send.post(request_body=mail) | |
| return {"status": "success"} | |
| email_agent_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=email_agent_instructions, | |
| model="gpt-4o-mini", | |
| tools=[send_email], | |
| model_settings=ModelSettings(tool_choice="required"), | |
| ) | |