Casting FindGameObjectsByTag to another type

Hi guys, I am trying to retrieve all GameObjects with a certain tag on the scene during every update call. GameObject.FindGameObjectsWithTag() retrieves an [] of GameObjectsbut Its no use for me because I have a specific class which is of type Agent. I wrote my own “version” of what I thought that method could be, but Its not performing similar to GameObject.FindGameObjectsWithTag() method, It doesn’t seem to retrieve properly the agents . I have a previous version of the project where I don’t implement Agent type specifically and instead use GameObject and everything is fine. But know I have to implement a KDTree data structure to optimize my script and it does not accept GameObject as type.

Any tips / help would be great! thanks

This is my version of GameObject.FindGameObjectsWithTag()

  private List<Agent> FindObjectsWithTag(string tag)
    {
        List<Agent> data = new List<Agent>();
        Agent [] allObjects = UnityEngine.Object.FindObjectsOfType<Agent>();
        foreach (Agent item in allObjects)
        {
            if (item.gameObject.tag == tag ) data.Add(item);
        }

        return data;
    }

@JVene, sorry for not clarifying that part, Agent is a class attached to a prefab. The KDTree class does not accept a type of GameObject because its is not a valid constraint for its Generic type T because its not an interface or a sealed class. So it only accepts a type Component for its type constraint, This is the reason I have to use my type Agent in the KDTree.

 public class KdTree<T> : IEnumerable<T>, IEnumerable 
        where T : Component