you can create an action (type: called by other action) and in this action add the actionparts to send the npc to the positions and loop it. Wrap all in a condition to stop the loop.
- if condition "npc_walking" is true
   - send npc to position B and wait
   - play animation ... and wait
   - send npc to position A and wait
   - jump to actionpart #1
- end
call this action at the beginning of the scene or whenever you need it
in the action when talking to the npc
- quit the action
- change the condition "npc_walking" to false
- start your dialogue
after the dialoge, change the condition back to true and call the action again.
quick example: