From a481b3330c1697d629e504777a72d7cfcd8ab147 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Tue, 29 Jul 2025 15:38:02 +0200 Subject: [PATCH] feat: add mail inbox tools Signed-off-by: Jana Peper --- ex_app/lib/agent.py | 1 + ex_app/lib/all_tools/mail.py | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ex_app/lib/agent.py b/ex_app/lib/agent.py index 5da413e..f67092c 100644 --- a/ex_app/lib/agent.py +++ b/ex_app/lib/agent.py @@ -67,6 +67,7 @@ def call_model( Today is {CURRENT_DATE}. Intuit the language the user is using (there is no tool for this, you will need to guess). Reply in the language intuited. Do not output the language you intuited. Only use tools if you cannot answer the user without them. +Always check for the mail account id before requesting a folder list. Only use the duckduckgo_results_json tool if the user explicitly asks for a web search. You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found. You can check which calendars exist using the list_calendars tool, if a calendar can not be found. diff --git a/ex_app/lib/all_tools/mail.py b/ex_app/lib/all_tools/mail.py index fc03a45..282f6b1 100644 --- a/ex_app/lib/all_tools/mail.py +++ b/ex_app/lib/all_tools/mail.py @@ -49,18 +49,39 @@ def send_email(subject: str, body: str, account_id: int, from_email: str, to_ema def get_mail_account_list(): """ Lists all available email accounts including their account id - :param subject: The subject of the email - :param body: The body of the email - :param account_id: The id of the account to send from - :param to_emails: The emails to send """ return nc.ocs('GET', '/ocs/v2.php/apps/mail/account/list') + + + @tool + @safe_tool + def get_mail_folder_list(account_id: int): + """ + Lists all mail folders for an account. You need to get the correct account id matching the request first before using this tool. + :param account_id: The id of the account to list as integer, obtainable via get_mail_account_list + """ + + return nc.ocs('GET', '/ocs/v2.php/apps/mail/mailbox/list', json={'accountId': account_id}) + + + @tool + @safe_tool + def list_mails(folder_id: int, n_mails: int = 30): + """ + Lists all messages in a mailbox folder. You need to get the correct folder id matching the request first before using this tool. + :param folder_id: The id of the folder to list as integer, obtainable via get_mail_folder_list + :param n_mails: The number of mails to receive. Optional, default is 30 + :return: a list of mails/messages, including timestamps + """ + return nc.ocs('GET', '/ocs/v2.php/apps/mail/mailbox/messages/list', json={'mailboxId': folder_id, 'limit': n_mails}) return [ send_email, - get_mail_account_list + get_mail_account_list, + get_mail_folder_list, + list_mails, ] def get_category_name():