This study deals with the development of a mechanism which can autonomously and automatically control the discharge gap for achieving electrical discharge machining (EDM) in an almost isolated space. This is so that a microrobot equipped with the mechanism can create a long, complicated curved hole, a hole that could not be formed by conventional machining methods. Holes formed by conventional machining methods are generally straight, so pipelines built in a variety of mechanical apparatuses consist of straight or polygonal lines. Such dearth of variety in realizable hole shapes can sometimes cause fundamental problems. A typical example of the problems appears in the design and production of water channels, i.e., pipelines built in metal molds to achieve appropriate thermal controls in molding processes. Specifically, the low variety of hole shapes prevents the shapes and positions of water channels from being optimized for the best thermal control in molding. Therefore, the development of a new method for machining curved holes has been needed. To meet this needed, we have conceived a method of machining curved holes by employing a microrobot that can perform EDM. A long, complicated curved hole can be created by making the microrobot perform stable EDM while moving along a long, complicated, curved trajectory in a workpiece. In order to realize this concept, the microrobot must have the capability to autonomously and automatically control the discharge gap in such an almost isolated space as the bottom or end of a curved hole. Accordingly, this study devises a new mechanism to give the microrobot this capability, and it calls the mechanism the “automatic discharge gap controller” (ADGC). The main components of ADGC are an electrode and power supply for EDM and a bidirectional actuator in which shape memory alloy (SMA) is employed. The results obtained from the experiments using a prototype of the ADGC prove that the ADGC has the capability of performing stable EDM by controlling the discharge gap autonomously and automatically without any other actuators.