From 265210e4b9707265eb9935990d7a1bad23ee9853 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Tue, 29 Jul 2025 15:38:02 +0200 Subject: [PATCH 1/3] feat: add mail inbox tools Signed-off-by: Jana Peper --- ex_app/lib/agent.py | 2 ++ ex_app/lib/all_tools/mail.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ex_app/lib/agent.py b/ex_app/lib/agent.py index 4c10b76..f194ccb 100644 --- a/ex_app/lib/agent.py +++ b/ex_app/lib/agent.py @@ -139,6 +139,8 @@ async def call_model( system_prompt_text += "Use the find_person_in_users tool to find a person's userId and user details.\n" if tool_enabled("find_details_of_current_user"): system_prompt_text += "Use the find_details_of_current_user tool to find the current user's location.\n" + if tool_enabled("list_mails"): + system_prompt_text += "Always check for the mail account id before requesting a folder list.\n" if task['input'].get('memories', None) is not None: 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" diff --git a/ex_app/lib/all_tools/mail.py b/ex_app/lib/all_tools/mail.py index bf7838c..5f3e2e5 100644 --- a/ex_app/lib/all_tools/mail.py +++ b/ex_app/lib/all_tools/mail.py @@ -53,11 +53,36 @@ async def get_mail_account_list(): """ return await 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/ocs/mailboxes', 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', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails}) return [ send_email, - get_mail_account_list + get_mail_account_list, + get_mail_folder_list, + list_mails, ] def get_category_name(): From 1940abf883a604831a1472a24aaad250c02fa964 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Wed, 6 May 2026 15:54:15 +0200 Subject: [PATCH 2/3] fix: make async Signed-off-by: Jana Peper --- ex_app/lib/agent.py | 1 - ex_app/lib/all_tools/mail.py | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ex_app/lib/agent.py b/ex_app/lib/agent.py index f194ccb..2667fa4 100644 --- a/ex_app/lib/agent.py +++ b/ex_app/lib/agent.py @@ -90,7 +90,6 @@ def export_conversation(checkpointer): # prepare the to-serialize blob state = {"last_config": last_config, "last_checkpoint": last_checkpoint} serialized_state = JsonPlusSerializer().dumps(state) - print(serialized_state) # sign the serialized state conversation_token = add_signature(serialized_state.decode('utf-8'), key) return conversation_token diff --git a/ex_app/lib/all_tools/mail.py b/ex_app/lib/all_tools/mail.py index 5f3e2e5..fde1772 100644 --- a/ex_app/lib/all_tools/mail.py +++ b/ex_app/lib/all_tools/mail.py @@ -57,25 +57,25 @@ async def get_mail_account_list(): @tool @safe_tool - def get_mail_folder_list(account_id: int): + async 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/ocs/mailboxes', json={'accountId': account_id}) + return await nc.ocs('GET', '/ocs/v2.php/apps/mail/ocs/mailboxes', json={'accountId': account_id}) @tool @safe_tool - def list_mails(folder_id: int, n_mails: int = 30): + async 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', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails}) + print(await nc.ocs('GET', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails})) + return await nc.ocs('GET', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails}) return [ From 993ff27244a13bb46c25b45c27ab24498174bafc Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Wed, 6 May 2026 16:52:46 +0200 Subject: [PATCH 3/3] fix: shorter descriptions Signed-off-by: Jana Peper --- ex_app/lib/all_tools/mail.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ex_app/lib/all_tools/mail.py b/ex_app/lib/all_tools/mail.py index fde1772..cc59877 100644 --- a/ex_app/lib/all_tools/mail.py +++ b/ex_app/lib/all_tools/mail.py @@ -59,7 +59,7 @@ async def get_mail_account_list(): @safe_tool async 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. + Lists all mail folders for an email account :param account_id: The id of the account to list as integer, obtainable via get_mail_account_list """ return await nc.ocs('GET', '/ocs/v2.php/apps/mail/ocs/mailboxes', json={'accountId': account_id}) @@ -69,12 +69,11 @@ async def get_mail_folder_list(account_id: int): @safe_tool async 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. + Lists all messages in a mailbox folder :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 """ - print(await nc.ocs('GET', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails})) return await nc.ocs('GET', f'/ocs/v2.php/apps/mail/ocs/mailboxes/{folder_id}/messages', json={'limit': n_mails})