Try just:
if [ condition ]; then
echo "then branch "
start_agent
else
echo "else branch"
start_agent
fi
if this works then it's your ps -ef ....
line that is not doing what you expect.
Additionally you can try what shellter suggests set -vx
for an "echo style" debug.