| 1 | from __future__ import annotations |
| 2 | |
| 3 | from helpers.tool import Response |
| 4 | from tools import response as core_response |
| 5 | |
| 6 | from plugins._goal.tools import goal |
| 7 | |
| 8 | |
| 9 | _CONTINUE_MARKER = "_goal_continue" |
| 10 | |
| 11 | |
| 12 | class ResponseTool(core_response.ResponseTool): |
| 13 | async def execute(self, **kwargs) -> Response: |
| 14 | response = await super().execute(**kwargs) |
| 15 | current_goal = goal.get_goal(self.agent.context.id) |
| 16 | if not current_goal or current_goal.get("status") != "active": |
| 17 | return response |
| 18 | |
| 19 | response.break_loop = False |
| 20 | response.message = ( |
| 21 | "Goal still active. Continue working autonomously and make safe, in-scope " |
| 22 | "choices yourself. Call goal update complete when satisfied, or blocked only " |
| 23 | "when no viable in-scope path remains." |
| 24 | ) |
| 25 | response.additional = {**(response.additional or {}), _CONTINUE_MARKER: True} |
| 26 | return response |
| 27 | |
| 28 | async def after_execution(self, response: Response, **kwargs): |
| 29 | additional = response.additional or {} |
| 30 | if additional.pop(_CONTINUE_MARKER, False): |
| 31 | self.agent.hist_add_tool_result(self.name, response.message, **additional) |
| 32 | await super().after_execution(response, **kwargs) |