Agent Zero AI framework
refactor: replace email_update tool with response break_loop param
linuztx25a7a25973a6
diff --git a/plugins/_email_integration/extensions/python/system_prompt/_20_email_context.py b/plugins/_email_integration/extensions/python/system_prompt/_20_email_context.pyindex aa7d21215..ec3aa49e1 100644--- a/plugins/_email_integration/extensions/python/system_prompt/_20_email_context.py+++ b/plugins/_email_integration/extensions/python/system_prompt/_20_email_context.py@@ -20,6 +20,3 @@ class EmailContextPrompt(Extension):system_prompt.append(self.agent.read_prompt("fw.email.system_context_reply.md"))- system_prompt.append(- self.agent.read_prompt("fw.email.tool_email_update.md")- )diff --git a/plugins/_email_integration/extensions/python/tool_execute_after/_50_email_attachments.py b/plugins/_email_integration/extensions/python/tool_execute_after/_50_email_attachments.pydeleted file mode 100644index e7f37bd91..000000000--- a/plugins/_email_integration/extensions/python/tool_execute_after/_50_email_attachments.py+++ /dev/null@@ -1,25 +0,0 @@-"""Intercept response tool to capture email attachments."""--from helpers.extension import Extension-from helpers.print_style import PrintStyle-from plugins._email_integration.helpers.dispatcher import CTX_EMAIL_HANDLER, CTX_EMAIL_ATTACHMENTS---class EmailResponseAttachments(Extension):-- async def execute(self, tool_name: str = "", **kwargs):- if tool_name != "response":- return- if not self.agent:- return- if not self.agent.context.data.get(CTX_EMAIL_HANDLER):- return-- tool = self.agent.loop_data.current_tool- if not tool:- return-- attachments = tool.args.get("attachments", [])- if attachments:- self.agent.context.data[CTX_EMAIL_ATTACHMENTS] = attachments- PrintStyle.info(f"Email: queued {len(attachments)} attachment(s)")diff --git a/plugins/_email_integration/extensions/python/tool_execute_after/_50_email_response.py b/plugins/_email_integration/extensions/python/tool_execute_after/_50_email_response.pynew file mode 100644index 000000000..af16f7ae1--- /dev/null+++ b/plugins/_email_integration/extensions/python/tool_execute_after/_50_email_response.py@@ -0,0 +1,60 @@+"""Intercept response tool in email sessions for attachments and break_loop."""++from helpers.extension import Extension+from helpers.print_style import PrintStyle+from helpers.tool import Response+from plugins._email_integration.helpers.dispatcher import CTX_EMAIL_HANDLER, CTX_EMAIL_ATTACHMENTS+++class EmailResponseIntercept(Extension):++ async def execute(+ self, tool_name: str = "", response: Response | None = None, **kwargs,+ ):+ if tool_name != "response":+ return+ if not self.agent:+ return+ context = self.agent.context+ if not context.data.get(CTX_EMAIL_HANDLER):+ return++ tool = self.agent.loop_data.current_tool+ if not tool:+ return++ # Capture attachments for later (process_chain_end) or inline send+ attachments = tool.args.get("attachments", [])+ if attachments:+ context.data[CTX_EMAIL_ATTACHMENTS] = attachments++ # Check break_loop arg from agent+ agent_break = tool.args.get("break_loop", True)+ if agent_break is False and response:+ await self._send_inline(context, tool, response)++ async def _send_inline(+ self, context, tool, response: Response,+ ):+ from plugins._email_integration.helpers.handler import send_email_reply++ agent = self.agent+ assert agent is not None++ text = tool.args.get("text", tool.args.get("message", ""))+ attachments = context.data.pop(CTX_EMAIL_ATTACHMENTS, [])++ if attachments:+ PrintStyle.info(f"Email: sending update with {len(attachments)} attachment(s)")++ error = await send_email_reply(context, text, attachments or None)++ if error:+ result = agent.read_prompt("fw.email.update_error.md", error=error)+ else:+ result = agent.read_prompt("fw.email.update_ok.md")++ # Override response: don't break loop, add result to history+ response.break_loop = False+ response.message = result+ agent.hist_add_tool_result("response", result)diff --git a/plugins/_email_integration/prompts/fw.email.system_context.md b/plugins/_email_integration/prompts/fw.email.system_context.mdindex 3b2da2fdf..97072d51b 100644--- a/plugins/_email_integration/prompts/fw.email.system_context.md+++ b/plugins/_email_integration/prompts/fw.email.system_context.md@@ -1,3 +1,4 @@-you are communicating via email, user sent email message-use response tool to send reply — response sent as email reply automatically-be concise, professional, clear+email session user communicates via email+response tool sends reply automatically+before each action inform user next step then execute+long tasks break_loop false sends progress without ending loopdiff --git a/plugins/_email_integration/prompts/fw.email.system_context_reply.md b/plugins/_email_integration/prompts/fw.email.system_context_reply.mdindex aaa6a52d0..d9fc07391 100644--- a/plugins/_email_integration/prompts/fw.email.system_context_reply.md+++ b/plugins/_email_integration/prompts/fw.email.system_context_reply.md@@ -1,21 +1,35 @@## Email conversation-you are in an email conversation user communicates via email-your response (via response tool) will be sent as email reply automatically-be concise professional clear-do not include email headers or signatures — they are added automatically+email session user communicates via email+response tool sends reply+before every action inform user+what you will do next then execute-### Progress updates-for long tasks use email_update tool to send progress emails without ending your task-use response tool only for the final answer+### progress updates+long tasks > response with "break_loop"+false sends email without ending loop+omit or true for final answer+~~~json+{+ ...+ "tool_name": "response",+ "tool_args": {+ "text": "Completed step 1...",+ "break_loop": false+ }+}+~~~-### Sending file attachments-to attach files to your email reply add attachments list with absolute file paths:+### file attachments+include file paths in attachments array~~~json{+ ..."tool_name": "response","tool_args": {- "text": "Here is the file you requested.",- "attachments": ["/path/to/file.txt"]+ "text": "Here is...",+ "attachments": [+ "/path/file.txt"+ ]}}~~~diff --git a/plugins/_email_integration/prompts/fw.email.tool_email_update.md b/plugins/_email_integration/prompts/fw.email.tool_email_update.mddeleted file mode 100644index 3cbcbfa35..000000000--- a/plugins/_email_integration/prompts/fw.email.tool_email_update.md+++ /dev/null@@ -1,28 +0,0 @@-### email_update-send progress or status email to user without ending your task-use when working on long tasks keep user informed while continuing work-does NOT end your agentic loop use "response" tool for final answer-usage:-~~~json-{- ...- "tool_name": "email_update",- "tool_args": {- "text": "... Completed step 1 of 3..."- }-}-~~~--optional attach files with attachments-~~~json-{- ...- "tool_name": "email_update",- "tool_args": {- "text": "... preliminary results ...",- "attachments": [- "/path/report.csv"- ]- }-}-~~~diff --git a/plugins/_email_integration/tools/email_update.py b/plugins/_email_integration/tools/email_update.pydeleted file mode 100644index 4257a2b75..000000000--- a/plugins/_email_integration/tools/email_update.py+++ /dev/null@@ -1,44 +0,0 @@-"""Send progress email without ending the agent loop."""--from helpers.tool import Tool, Response-from plugins._email_integration.helpers.dispatcher import CTX_EMAIL_HANDLER---class EmailUpdate(Tool):-- async def execute(self, **kwargs) -> Response:- if not self.agent.context.data.get(CTX_EMAIL_HANDLER):- return Response(- message=self.agent.read_prompt(- "fw.email.update_error.md",- error="not in an email session"),- break_loop=False,- )-- text = self.args.get("text", "")- if not text:- return Response(- message=self.agent.read_prompt(- "fw.email.update_error.md",- error="text is required",- ),- break_loop=False,- )-- attachments = list(self.args.get("attachments", []))-- from plugins._email_integration.helpers.handler import send_email_reply- error = await send_email_reply(self.agent.context, text, attachments or None)-- if error:- return Response(- message=self.agent.read_prompt(- "fw.email.update_error.md", error=error,- ),- break_loop=False,- )-- return Response(- message=self.agent.read_prompt("fw.email.update_ok.md"),- break_loop=False,- )