In the last few decades, with the development of technology in the field of microprocessor, digital communication and instrumentation, several independent systems have been developed to achieve a common goal. This will replace a few more simple systems instead of a complex system. The advantages of this method can be the ability to develop and reliability of the system. In all cases mentioned, the control rule is required to control the coordinating agents. In this thesis, the goal is to optimally control the formation of multi-agent systems of the second order. To this aim, we first introduce a variety of dynamic models for describing the math of the motion of the agents. In the following, the aim of pursuing the problem for the two integral operators is expressed and by obtaining the equations of the agent space state and defining the appropriate cost function for pursuit The objective and minimum energy form the optimal control problem by solving the optimal control problem of the optimal control law for pursuit. In the following, we discuss the consensus question for the first and second order Multi-Agent systems and simulate the consensus question. Then, we describe different strategies of Formation control, non-interference strategies, and finally, by presenting A comprehensive model of the Formation control problem expresses the desired control requirements (goal tracking, non-collision) in the form of cost functions and maintains the formation in the form of control. In other words, we formulate the control of the formation in the form of an optimal control problem with non-square cost functions. Due to the non-squareness of the cost of non-interference and target tracking functions, one can not use the usual optimal control approaches (such as linear stabilization square control). By providing a method for solving the problem of optimal control with non-square functions, the problem of optimal control of the formation is solved and obtaining the optimal control rule Finaly, the simulation of this control rule in differentcondition. Ke ywords : Multi-Agent systems, Formation, Optimal control, Consensus