ranranrunforit/deep_research
0
1import os2from typing import Dict3 4import sendgrid5from sendgrid.helpers.mail import Email, Mail, Content, To6from agents import Agent, function_tool, AsyncOpenAI, OpenAIChatCompletionsModel7 8gemini_client = AsyncOpenAI(base_url="https://generativelanguage.googleapis.com/v1beta/openai/", api_key=os.getenv('GOOGLE_API_KEY'))9 10gemini_model = OpenAIChatCompletionsModel(model="gemini-2.0-flash", openai_client=gemini_client)11 12 13 14@function_tool15def send_email(subject: str, html_body: str) -> Dict[str, str]:16 """ Send an email with the given subject and HTML body """17 sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))18 from_email = Email("cz78@illinois.edu") # put your verified sender here19 to_email = To("ch315868@dal.ca") # put your recipient here20 content = Content("text/html", html_body)21 mail = Mail(from_email, to_email, subject, content).get()22 response = sg.client.mail.send.post(request_body=mail)23 print("Email response", response.status_code)24 return {"status": "success"}25 26INSTRUCTIONS = """You are able to send a nicely formatted HTML email based on a detailed report.27You will be provided with a detailed report. You should use your tool to send one email, providing the 28report converted into clean, well presented HTML with an appropriate subject line."""29 30email_agent = Agent(31 name="Email agent",32 instructions=INSTRUCTIONS,33 tools=[send_email],34 model=gemini_model,35)36 