Optimization and Optimal Control of Agent