Reset enviroment

I am training multiple agents with the same brain. When they reach the goal, all of them has to restart, however if I call EndEpisode() method only the agent that did called this method will restart.
I want to find a way that whenever an agent call the EndEpisode() method all the other agents also restart. I have found this thread where they talk about it: https://discussions.unity.com/t/787559
I also read the documentation of how Academy.Instance.OnEnvironmentReset += ResetMethod works, but I did not understand it. How do I implement this Academy.Instance.OnEnvironmentReset, what do I write in the ResetMethod?

If you just need to reset your agents, you could handle that in a central agent controller script. Similar to the DecisionRequester component, but not attached to any specific agent instance. Something like this:

using Unity.MLAgents;
using UnityEngine;

public class AgentController : MonoBehaviour
{
    private MyAgent[] agents;

    private void Awake()
    {
        agents = FindObjectsOfType<MyAgent>();
        Academy.Instance.AgentPreStep += OnAgentPreStep;
    }

    private void OnDestroy()
    {
        if (Academy.IsInitialized)
        {
            Academy.Instance.AgentPreStep -= OnAgentPreStep;
        }
    }

    private void OnAgentPreStep(int academyStepCount)
    {
        bool resetAll = false;

        foreach (MyAgent agent in agents)
        {
            resetAll = resetAll || agent.MustReset; // your custom reset bool
        }

        foreach (MyAgent agent in agents)
        {
            if (resetAll)
            {
                agent.EndEpisode();
            }
            else
            {
                agent.RequestDecision();
            }
        }
    }
}