Addded generate_action utility function