File size: 1,541 Bytes
45d075b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Import libraries
import os
import requests
from mailjet_rest import Client
from agents import Agent, function_tool

# Create function tool to send email 
@function_tool
def send_email(subject: str, html_body: str, to:str):
    api_key = os.environ['MJ_APIKEY_PUBLIC']
    api_secret = os.environ['MJ_APIKEY_PRIVATE'] 

    # Create the mailjet client 
    mailjet = Client(auth=(api_key, api_secret), version='v3.1')

    # Define the payload 
    data = {
    'Messages': [
                    {
                            "From": {
                                    "Email": "youhorng.kean@gmail.com"
                            },
                            "To": [
                                    {
                                            "Email": to
                                    }
                            ],
                            "Subject": subject,
                            "HTMLPart": html_body
                    }
            ]
    }

    # Send the email
    result = mailjet.send.create(data=data)

    return result.json()


# Define instructions for the email agent
EMAIL_INSTRUCTIONS = """You are able to send a nicely formatted HTML email based on a detailed report.
You will be provided with a detailed report and a recipient email. Use your tool to send one email, 
providing the report as HTML with an appropriate subject line."""

# Create the email_agent
email_agent = Agent(
    name="Email Agent",
    instructions=EMAIL_INSTRUCTIONS,
    tools=[send_email],
    model="gpt-4o-mini"
)