Hello Robert.
When the agent is updated, the agentID and the key should not be changed.
I have been testing it on my environment and both the key and the agent ID remained the same. I recommend you to take a look at the upgrade guide to follow the right steps. You can find it here
root@ubuntuagent:/home/vagrant# WAZUH_MANAGER="10.2.0.4" apt-get install wazuh-agent=4.0.0-1
......
root@ubuntuagent:/home/vagrant# /var/ossec/bin/ossec-control status
wazuh-modulesd not running...
ossec-logcollector not running...
ossec-syscheckd not running...
ossec-agentd not running...
ossec-execd not running...
root@ubuntuagent:/home/vagrant# cat /var/ossec/etc/client.keys
004 ubuntuagent any 68b26925882ed905632025fdf4dd8e5b223ae9044f482882164b40934b4440c4
after updating
root@ubuntuagent:/home/vagrant# apt upgrade wazuh-agent
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
wazuh-agent is already the newest version (4.3.7-1).
Calculating upgrade... Done
The following packages have been kept back:
thermald ubuntu-advantage-tools
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
root@ubuntuagent:/home/vagrant# cat /var/ossec/etc/client.keys
004 ubuntuagent any 68b26925882ed905632025fdf4dd8e5b223ae9044f482882164b40934b4440c4
root@ubuntuagent:/home/vagrant#
As you can see, the key and the ID remained the same.