[docs]asyncdefexecute_shell_command(command:str,timeout:int=300,**kwargs:Any,)->ToolResponse:"""Execute given command and return the return code, standard output and error within <returncode></returncode>, <stdout></stdout> and <stderr></stderr> tags. Args: command (`str`): The shell command to execute. timeout (`float`, defaults to `300`): The maximum time (in seconds) allowed for the command to run. Returns: `ToolResponse`: The tool response containing the return code, standard output, and standard error of the executed command. """proc=awaitasyncio.create_subprocess_shell(command,stdout=asyncio.subprocess.PIPE,stderr=asyncio.subprocess.PIPE,bufsize=0,)try:awaitasyncio.wait_for(proc.wait(),timeout=timeout)stdout,stderr=awaitproc.communicate()stdout_str=stdout.decode("utf-8")stderr_str=stderr.decode("utf-8")returncode=proc.returncodeexceptasyncio.TimeoutError:stderr_suffix=(f"TimeoutError: The command execution exceeded "f"the timeout of {timeout} seconds.")returncode=-1try:proc.terminate()stdout,stderr=awaitproc.communicate()stdout_str=stdout.decode("utf-8")stderr_str=stderr.decode("utf-8")ifstderr_str:stderr_str+=f"\n{stderr_suffix}"else:stderr_str=stderr_suffixexceptProcessLookupError:stdout_str=""stderr_str=stderr_suffixreturnToolResponse(content=[TextBlock(type="text",text=(f"<returncode>{returncode}</returncode>"f"<stdout>{stdout_str}</stdout>"f"<stderr>{stderr_str}</stderr>"),),],)