I had this error on ubuntu 20.04 single node as ELK 7.17.25 server and a win 11 with elastic-agent 7.17.25. After a bout 15 minutes, agent status gone unhealthy. Elastic agent has no full support for win 11 (Base on This link)
I read this page but Elastic Agent has full support for Ubuntu 24.04. It is not bad decision to check this: Go to Kibana > Endpoints > Click on Policy status of that End point and check all the Policy Responses to be Success. Maybe you have a problem there.