Skip to content

Commit 5a1defe

Browse files
authored
Merge pull request #54 from nextcloud/feat/mail-inbox
Feat: add mail inbox tools
2 parents 57d7fe2 + 993ff27 commit 5a1defe

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

ex_app/lib/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def export_conversation(checkpointer):
9090
# prepare the to-serialize blob
9191
state = {"last_config": last_config, "last_checkpoint": last_checkpoint}
9292
serialized_state = JsonPlusSerializer().dumps(state)
93-
print(serialized_state)
9493
# sign the serialized state
9594
conversation_token = add_signature(serialized_state.decode('utf-8'), key)
9695
return conversation_token
@@ -139,6 +138,8 @@ async def call_model(
139138
system_prompt_text += "Use the find_person_in_users tool to find a person's userId and user details.\n"
140139
if tool_enabled("find_details_of_current_user"):
141140
system_prompt_text += "Use the find_details_of_current_user tool to find the current user's location.\n"
141+
if tool_enabled("list_mails"):
142+
system_prompt_text += "Always check for the mail account id before requesting a folder list.\n"
142143

143144
if task['input'].get('memories', None) is not None:
144145
system_prompt_text += "You can remember things from other conversations with the user. If relevant, take into account the following memories:\n\n" + "\n".join(task['input']['memories']) + "\n\n"

ex_app/lib/all_tools/mail.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,35 @@ async def get_mail_account_list():
5353
"""
5454

5555
return await nc.ocs('GET', '/ocs/v2.php/apps/mail/account/list')
56+
57+
58+
@tool
59+
@safe_tool
60+
async def get_mail_folder_list(account_id: int):
61+
"""
62+
Lists all mail folders for an email account
63+
:param account_id: The id of the account to list as integer, obtainable via get_mail_account_list
64+
"""
65+
return await nc.ocs('GET', '/ocs/v2.php/apps/mail/ocs/mailboxes', json={'accountId': account_id})
66+
67+
68+
@tool
69+
@safe_tool
70+
async def list_mails(folder_id: int, n_mails: int = 30):
71+
"""
72+
Lists all messages in a mailbox folder
73+
:param folder_id: The id of the folder to list as integer, obtainable via get_mail_folder_list
74+
:param n_mails: The number of mails to receive. Optional, default is 30
75+
:return: a list of mails/messages, including timestamps
76+
"""
77+
return await nc.ocs('GET', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails})
5678

5779

5880
return [
5981
send_email,
60-
get_mail_account_list
82+
get_mail_account_list,
83+
get_mail_folder_list,
84+
list_mails,
6185
]
6286

6387
def get_category_name():

0 commit comments

Comments
 (0)