| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 | 
							- list_emails_function = """
 
- {
 
-     "type": "function",
 
-     "function": {
 
-         "name": "list_emails",
 
-         "description": "Return a list of emails matching an optionally specified query.",
 
-         "parameters": {
 
-             "type": "dic",
 
-             "properties": [
 
-                 {
 
-                     "maxResults": {
 
-                         "type": "integer",
 
-                         "description": "The default maximum number of emails to return is 100; the maximum allowed value for this field is 500."
 
-                     }
 
-                 },              
 
-                 {
 
-                     "query": {
 
-                         "type": "string",
 
-                         "description": "One or more keywords in the email subject and body, or one or more filters. There can be 6 types of filters: 1) Field-specific Filters: from, to, cc, bcc, subject; 2) Date Filters: before, after, older than, newer than); 3) Status Filters: read, unread, starred, importatant; 4) Attachment Filters: has, filename or type; 5) Size Filters: larger, smaller; 6) logical operators (or, and, not)."
 
-                     }
 
-                 }
 
-             ],
 
-             "required": []
 
-         }
 
-     }
 
- }
 
- """
 
- get_email_function = """
 
- {
 
-     "type": "function",
 
-     "function": {
 
-         "name": "get_email_detail",
 
-         "description": "Get detailed info about a specific email",
 
-         "parameters": {
 
-             "type": "dict",
 
-             "properties": [
 
-                 {
 
-                     "detail": {
 
-                         "type": "string",
 
-                         "description": "what detail the user wants to know about - two possible values: body or attachment"
 
-                     }
 
-                 },
 
-                 {
 
-                     "which": {
 
-                         "type": "string",
 
-                         "description": "which email to get detail about - possible values include: 'first', 'second', ..., 'last', 'from ...', and 'subject ...'"
 
-                     }
 
-                 },
 
-             ],
 
-             "required": ["detail", "which"]
 
-         }
 
-     }
 
- }
 
- """
 
- send_email_function = """
 
- {
 
-     "type": "function",
 
-     "function": {
 
-         "name": "send_email",
 
-         "description": "Compose, reply, or forward email",
 
-         "parameters": {
 
-             "type": "dict",
 
-             "properties": [
 
-                 {
 
-                     "action": {
 
-                         "type": "string",
 
-                         "description": "Whether to compose, reply, or forward an email"
 
-                     }
 
-                 },
 
-                 {
 
-                     "to": {
 
-                         "type": "string",
 
-                         "description": "The recipient of the email"
 
-                     }
 
-                 },
 
-                 {
 
-                     "subject": {
 
-                         "type": "string",
 
-                         "description": "The email subject"
 
-                     }
 
-                 },
 
-                 {
 
-                     "body": {
 
-                         "type": "string",
 
-                         "description": "The email content"
 
-                     }
 
-                 },                                
 
-                 {
 
-                     "email_id": {
 
-                         "type": "string",
 
-                         "description": "the email id to reply or forward to"
 
-                     }
 
-                 }
 
-             ],
 
-             "required": ["action", "to", "subject", "body"]
 
-         }
 
-     }
 
- }
 
- """
 
- get_pdf_summary_function = """
 
- {
 
-     "type": "function",
 
-     "function": {
 
-         "name": "get_pdf_summary",
 
-         "description": "get a summary of a PDF attachment",
 
-         "parameters": {
 
-             "type": "dict",
 
-             "properties": [
 
-                 {
 
-                     "file_name": {
 
-                         "type": "string",
 
-                         "description": "The name of the PDF file"
 
-                     }
 
-                 },
 
-             ],
 
-             "required": ["file_name"]
 
-         }
 
-     }
 
- }
 
- """
 
- create_draft_function = """
 
- {
 
-     "type": "function",
 
-     "function": {
 
-         "name": "create_draft",
 
-         "description": "Create a new, reply, or forward email draft",
 
-         "parameters": {
 
-             "type": "dict",
 
-             "properties": [
 
-                 {
 
-                     "action": {
 
-                         "type": "string",
 
-                         "description": "Whether to draft a new, reply, or forward an email"
 
-                     }
 
-                 },
 
-                 {
 
-                     "to": {
 
-                         "type": "string",
 
-                         "description": "The recipient of the email"
 
-                     }
 
-                 },
 
-                 {
 
-                     "subject": {
 
-                         "type": "string",
 
-                         "description": "The email subject"
 
-                     }
 
-                 },
 
-                 {
 
-                     "body": {
 
-                         "type": "string",
 
-                         "description": "The email content"
 
-                     }
 
-                 },                                
 
-                 {
 
-                     "email_id": {
 
-                         "type": "string",
 
-                         "description": "the email id to reply or forward to, or empty if draft a new email."
 
-                     }
 
-                 }
 
-             ],
 
-             "required": ["action", "to", "subject", "body", "email_id"]
 
-         }
 
-     }
 
- }
 
- """
 
- # for now, only allow for one draft email to be saved in a session
 
- # to support for multiple drafts, cf how get_email_detail after list_emails is implemented.
 
- send_draft_function = """
 
- {
 
-     "type": "function",
 
-     "function": {
 
-         "name": "send_draft",
 
-         "description": "Send a draft email",
 
-         "parameters": {
 
-             "type": "dict",
 
-             "properties": [
 
-                 {
 
-                     "id": {
 
-                         "type": "string",
 
-                         "description": "draft id"
 
-                     }
 
-                 },        
 
-             ],
 
-             "required": ["id"]        
 
-         }
 
-     }
 
- }
 
- """
 
- examples = """
 
- {"name": "list_emails", "parameters": {"query": "has:attachment larger:5mb"}}
 
- {"name": "list_emails", "parameters": {"query": "has:attachment"}}
 
- {"name": "list_emails", "parameters": {"query": "newer_than:1d"}}
 
- {"name": "list_emails", "parameters": {"query": "older_than:1d"}}
 
- {"name": "list_emails", "parameters": {"query": "is:unread"}}
 
- {"name": "list_emails", "parameters":  {"query": "<query> is:unread"}}
 
- {"name": "list_emails", "parameters":  {"query": "<query> is:read"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "body", "which": "first"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "body", "which": "last"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "body", "which": "second"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "body", "which": "subject <subject info>"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "from <sender info>"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "first"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "last"}}
 
- {"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "<email id>"}}
 
- {"name": "send_email", "parameters": {"action": "compose", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx"}}
 
- {"name": "send_email", "parameters": {"action": "reply", "to": "", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
 
- {"name": "send_email", "parameters": {"action": "forward", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
 
- {"name": "create_draft", "parameters": {"action": "new", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx", "email_id": ""}}
 
- {"name": "create_draft", "parameters": {"action": "reply", "to": "", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
 
- {"name": "create_draft", "parameters": {"action": "forward", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
 
- {"name": "send_draft", "parameters": {"id": "..."}}
 
- {"name": "get_pdf_summary", "parameters": {"file_name": "..."}}
 
- """
 
- system_prompt = f"""
 
- Environment: ipython
 
- Cutting Knowledge Date: December 2023
 
- Today Date: 1 December 2024
 
- Your name is Email Agent, an assistant that can perform all email related tasks for your user.
 
- Respond to the user's ask by making use of the following functions if needed.
 
- If no available functions can be used, just say "I don't know" and don't make up facts.
 
- Here is a list of available functions in JSON format:
 
- {list_emails_function}
 
- {get_email_function}
 
- {send_email_function}
 
- {get_pdf_summary_function}
 
- {create_draft_function}
 
- {send_draft_function}
 
- Example responses:
 
- {examples}
 
- """
 
 
  |