Is it possible to switch brains during training?

I want to set up two behaviours for one agent. One behaviour would be a patrolling type behaviour, and the other would be a ‘something has been detected’ behaviour.

Is this possible and, if so, what would the best way of achieving this be?

I was thinking of creating and training two agents separately and then having them perform inference in a scenario, but then instantiate/destroy them at the right moment so it would look as though the same agent changed behaviours. This would allow each behaviour to have it’s own unique set of observations, but would force them to train separately.

Yes it is, I recommend you to look the wallJump example in the example environment of mlagent repo. It uses 2 brains

I have looked at it. It switches between the brains during inference, not during training

Training two distinct agents should work for this. You could implement the physics in a separate class, so that both your agents receive observations from, and send actions to that common physics interface. Then it’s just a matter of calling RequestDecision/Action on whatever agent behaviour is applicable during inference. Some controller script would decide which agent is active or inactive depending on the situation, without having to instantiate or destroy any agents.

So could I attach two agent scripts to the same gameobject? I’m not sure how I’d switch between the two scripts during inference

I have only ever used the decision requester component to request decisions. I guess I could do it manually and switch between them where appropriate

1 Like