I need help with implementing Unity's NavMeshAgent follow Unity Spline Path

When my AI is in WhilePatroling Here it follows Spline Path with lag (freezes for a second and moves forward)
Here is code for AI:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Splines;

namespace MeenyAI.AIRuntime.Core
{
    public enum AIState
    {
        StartSearching,
        WhileSearching,
        StartPatrolling,
        WhilePatrolling,
        Following,
        StartWaiting,
        WhileWaiting
    }

    public class EnemyAICore : MonoBehaviour
    {
        public Transform Target { get; private set; }
        public bool HasTarget { get; private set; } = false;

        private AIState currentState = AIState.StartPatrolling;
        private bool isTargetPointSet;

        [SerializeField] private NavMeshAgent agent;

        [field: Header("AI Settings")]
        [SerializeField] private LayerMask targetMask;
        [SerializeField] private LayerMask obstacleMask;
        [field: SerializeField] public float seeRadius { get; private set; } = 25f;
        [field: SerializeField] public float seeFOV { get; private set; } = 220f;
        [field: SerializeField] public float attackRadius { get; private set; } = 5f;
        [field: SerializeField] public float attackFOV { get; private set; } = 90f; 
        [SerializeField] private float lostTargetTime = 1f;
        [SerializeField] private float searchTime = 5f;
        [SerializeField] private float hideBehindDoorTime = 2f;
        [SerializeField] private float hideBehindCornerTime = 3f;
        [SerializeField] private SplineContainer patrolPathContainer;
        private SplinePath patrolPath;
        private float patrolTime = 0f;

        [Header("AI Loop")]
        public bool loopEnabled = true;
        public float loopWaitTime = 0.2f;

        private AIRoom lastRoom;

        private void Start()
        {
            InitializePatrolPath();
            StartCoroutine(AILoop());
        }

        private void InitializePatrolPath()
        {
            var pathTransform = patrolPathContainer.transform.localToWorldMatrix;
            List<SplineSlice<Spline>> splineSlices = new List<SplineSlice<Spline>>();

            foreach (Spline spline in patrolPathContainer.Splines)
            {
                splineSlices.Add(new SplineSlice<Spline>(spline, new SplineRange(0, GetSize(spline.Knots)), pathTransform));
            }

            patrolPath = new SplinePath(splineSlices);
        }

        private IEnumerator AILoop()
        {
            WaitForSeconds loopWait = new WaitForSeconds(loopWaitTime);

            while (loopEnabled)
            {
                GetTarget();

                Debug.Log($"Distance to target: " + agent.remainingDistance);

                switch (currentState)
                {
                    case AIState.StartPatrolling:
                        StartPatrollingBehavior();
                        break;

                    case AIState.Following:
                        FollowingBehavior();
                        break;

                    case AIState.StartSearching:
                        lastRoom = AIPlayerInformations.Instance.PlayerCurrentRoom;
                        StartSearchingBehavior();
                        break;

                    case AIState.StartWaiting:
                        TrollBehavior();
                        break;
                }

                yield return loopWait;
            }
        }

        private void StartPatrollingBehavior()
        {
            currentState = AIState.WhilePatrolling;
            StartCoroutine(WhilePatrollingBehavior());
        }

        private IEnumerator WhilePatrollingBehavior()
        {
            while (currentState == AIState.WhilePatrolling)
            {
                Vector3 position = patrolPath.EvaluatePosition(patrolTime);
                FollowTarget(position);

                while (!isTargetPointSet)
                {
                    if (agent.remainingDistance < 0.1)
                        isTargetPointSet = true;

                    yield return new WaitForSeconds(0f);
                }

                isTargetPointSet = false;

                patrolTime += (float)(0.005f * Time.deltaTime);
                if (patrolTime > 1f) patrolTime = 0f;
            }
        }

        private void FollowingBehavior()
        {
            if (Target != null)
                FollowTarget(Target.position);
        }

        private void StartSearchingBehavior()
        {
            currentState = AIState.WhileSearching;
            SearchRoom();
        }

        private void TrollBehavior()
        {
            currentState = AIState.WhileWaiting;
            StartCoroutine(TrollCycle());
        }

        private void GetTarget()
        {
            Collider[] foundColliders = Physics.OverlapSphere(transform.position, seeRadius, targetMask);

            if (foundColliders.Length != 0)
            {
                Transform target = foundColliders[0].transform;
                Vector3 direction = (target.position - transform.position).normalized;

                if (Vector3.Angle(transform.forward, direction) < (seeFOV / 2))
                {
                    float distance = Vector3.Distance(transform.position, target.position);

                    if (!Physics.Raycast(transform.position, direction, distance, obstacleMask))
                    {
                        HasTarget = true;
                        Target = target;
                        currentState = AIState.Following;
                    }
                    else
                        CantFindTarget();
                }
                else
                    CantFindTarget();
            }
        }

        private void FollowTarget(Vector3 position)
        {
            agent.SetDestination(position);
        }

        private void CantFindTarget()
        {
            if (currentState == AIState.Following)
                currentState = AIState.StartSearching;

            LoseTarget();
        }

        private void LoseTarget()
        {
            HasTarget = false;
            Target = null;
        }

        private void SearchRoom()
        {
            StartCoroutine(SearchTimerBehavior());
            StartCoroutine(SearchSubBehavior());
        }

        private IEnumerator TrollCycle()
        {
            WaitForSeconds waitForDoor = new WaitForSeconds(hideBehindDoorTime);
            WaitForSeconds waitForCorner = new WaitForSeconds(hideBehindCornerTime);
            WaitForSeconds waitUpdate = new WaitForSeconds(loopWaitTime);

            GoToRandomPointsInRoom(lastRoom.Doors);
            isTargetPointSet = false;

            while (!isTargetPointSet)
            {
                if (agent.remainingDistance < 0.1)
                    isTargetPointSet = true;
                yield return waitUpdate;
            }

            yield return waitForDoor;
            isTargetPointSet = false;

            GoToRandomPointsInRoom(lastRoom.Corners);

            while (!isTargetPointSet)
            {
                if (agent.remainingDistance < 0.1)
                    isTargetPointSet = true;
                yield return waitUpdate;
            }

            yield return waitForCorner;

            if (currentState == AIState.WhileWaiting)
                currentState = AIState.StartPatrolling;
        }

        private IEnumerator SearchTimerBehavior()
        {
            WaitForSeconds wait = new WaitForSeconds(searchTime);
            yield return wait;

            if (currentState == AIState.WhileSearching)
                currentState = AIState.StartWaiting;
        }

        private IEnumerator SearchSubBehavior()
        {
            WaitForSeconds waitUpdate = new WaitForSeconds(loopWaitTime);
            isTargetPointSet = true;

            while (currentState == AIState.WhileSearching)
            {
                if (isTargetPointSet)
                    GoToRandomPointsInRoom(lastRoom.Points);

                isTargetPointSet = (agent.remainingDistance < 0.1);
                yield return waitUpdate;
            }
        }

        private void GoToRandomPointsInRoom(Transform[] array)
        {
            int randomIndex = Random.Range(0, array.Length);
            Transform point = array[randomIndex];
            FollowTarget(point.position);
        }

        private static int GetSize(IEnumerable toCount)
        {
            int count = 0;

            foreach (var part in toCount)
            {
                count += 1;
            }

            return count;
        }
    }
}

i got answer on stackoverflow: