live agent triggering on_user_message event first rather than on_agent_transfer

I created a agent transfer dialog,on triggering the intent it goes to liveagent node.
In live agent it should trigger the on_agent_transfer event,but it is triggerring on_user_message first and giving error that visitor_id is undefined.

some times it is triggering on_agent_transfer first,but sometimes it is triggering on_user_message first

can anyone please help me why it is doing like that