Checking environment for SSH_AUTH_SOCK is good for direct ssh connections.
If you use proxies (proxy_command) you might have a connction that looks like:
local -> hostA -> hostB -> hostC -> hostD
If agent forwarding is active on all those hosts, then SSH_AUTH_SOCK will be set and "contains" your ssh key from local on all hosts.
Now suppose agent forwarding is disabled on hostB but enabled on hostC. SSH_AUTH_SOCK will be set on hostD but it will actually be "empty". Of course the agent is forwarded but only from hostC to hostD. The chain is broken.
Now to check if actually the key is available on hostD you can simply call ssh-add. It will exit with code 1 in any case, but if the key is unavailable it will show this on stderr:
Could not open a connection to your authentication agent.
So you can check for the SSH_AUTH_SOCK plus make sure ssh_add has no output.
ssh-find-agentscript for finding and using existing ssh-agents, very handy! The repo has some examples in the README. You might be able to detect if ssh-agent is enabled like that, along with inspecting the SSH config files, rather than looking at the SSH output.