Liorlsa9's picture
Add initial implementation of deep research agents and email functionality
736beb3
import os
from typing import Dict
import sendgrid
from sendgrid.helpers.mail import Email, Mail, Content, To
from agents import Agent, function_tool
import markdown2
@function_tool
def send_email(subject: str, html_body: str) -> Dict[str, str]:
""" Send an email with the given subject and HTML body (markdown supported) """
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("liorsolomon.solid@gmail.com") # put your verified sender here
to_email = To("liorsolomon.solid@gmail.com") # put your recipient here
# Convert markdown to HTML and wrap in a basic template
html_content = markdown2.markdown(html_body)
html_template = f"""
<html>
<head>
<style>
body {{ font-family: Arial, sans-serif; margin: 2em; }}
h1, h2, h3 {{ color: #0074D9; }}
p {{ line-height: 1.6; }}
</style>
</head>
<body>
{html_content}
</body>
</html>
"""
content = Content("text/html", html_template)
mail = Mail(from_email, to_email, subject, content).get()
response = sg.client.mail.send.post(request_body=mail)
print("Email response", response.status_code)
return {"status": "success"}
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",
)