Define Guided mode via MAVLink

I am studying communication via MAVLink. For this purpose I use ESP32 as a companion computer, from which I want to send commands to fly to a point in Guided mode.
That is, the task is as follows: I turn on Guided mode via the remote control with a toggle switch, ESP32 sees it and starts sending commands to fly to a point.

I have been trying to determine when the copter goes into Guided mode.
I found that in the HEARTBEAT message there is a field MAV_MODE_FLAG which has a bit MAV_MODE_FLAG_DECODE_POSITION_GUIDED.
But the problem is that this bit is turned on every time there is a connection to the remote control.

What am I doing wrong? Why this bit does not show Guided mode but connection to the remote control? How do I correctly define the flight mode?