You need to make sure that the reboot action is last line that is executed. As per SMason's post you need to split it up into to separate procedures so that you can schedule the second half just before the first reboot so it will run in say 5min, giving enough time for the target machine to reboot.
Splitting up your agent procedures has another benefit, if you write it correctly you could use it on its own or in other future procedures saving you time in having to rewrite the same action over and over again.