| 1 | from helpers.tool import Tool, Response |
| 2 | |
| 3 | # example of a tool redefinition |
| 4 | # the original response tool is in python/tools/response.py |
| 5 | # for the example agent this version will be used instead |
| 6 | |
| 7 | class ResponseTool(Tool): |
| 8 | |
| 9 | async def execute(self, **kwargs): |
| 10 | print("Redefined response tool executed") |
| 11 | return Response(message=self.args["text"] if "text" in self.args else self.args["message"], break_loop=True) |
| 12 | |
| 13 | async def before_execution(self, **kwargs): |
| 14 | # self.log = self.agent.context.log.log(type="response", heading=f"{self.agent.agent_name}: Responding", content=self.args.get("text", "")) |
| 15 | # don't log here anymore, we have the live_response extension now |
| 16 | pass |
| 17 | |
| 18 | async def after_execution(self, response, **kwargs): |
| 19 | # do not add anything to the history or output |
| 20 | |
| 21 | if self.loop_data and "log_item_response" in self.loop_data.params_temporary: |
| 22 | log = self.loop_data.params_temporary["log_item_response"] |
| 23 | log.update(finished=True) # mark the message as finished |