Consider a graph G of groups such that each vertex group locally satisfies a nontrivial identity and each edge subgroup is properly included into the corresponding vertex groups and its index in at least one of them exceeds 2. We prove that if the fundamental group F of G is locally residually nilpotent then there exists a prime number p such that each edge subgroup is p′-isolated in the corresponding vertex group. We show also that if F is the free product of an arbitrary family of groups with one amalgamated subgroup or a multiple HNN-extension then the same result holds without restrictions on the indices of edge subgroups.