Files
agent-zero/plugins/_code_execution/tools/input.py
T

36 lines
1.6 KiB
Python

from helpers.tool import Tool, Response
from plugins._code_execution.tools.code_execution_tool import CodeExecution
class Input(Tool):
async def execute(self, keyboard="", **kwargs):
# normalize keyboard input
keyboard = keyboard.rstrip()
# keyboard += "\n" # no need to, code_exec does that
# terminal session number
session = int(self.args.get("session", 0))
destination = str(self.args.get("destination", "default") or "default")
from helpers.tool_policy import ensure_retired_host_tool_allowed, ensure_tool_allowed
ensure_tool_allowed(self.agent, "code_execution_tool", canonical_id="plugin:_code_execution:code_execution_tool", action="terminal")
if destination.strip() == "host":
ensure_retired_host_tool_allowed(self.agent, "input_remote")
args = {
"runtime": "terminal", "code": keyboard, "session": session,
"destination": destination,
}
cet = CodeExecution(self.agent, "code_execution_tool", "", args, self.message, self.loop_data)
cet.allow_running = True
cet.log = getattr(self, "log", None)
return await cet.execute(**args)
def get_log_object(self):
import uuid
return self.agent.context.log.log(type="code_exe", heading=f"icon://keyboard Using tool '{self.name}'", content="", kvps=self.args, id=str(uuid.uuid4()))
async def after_execution(self, response, **kwargs):
self.agent.hist_add_tool_result(self.name, response.message, id=self.log.id if self.log else "", **(response.additional or {}))