Alliteration gives the poem musicality and intensity.
In the second stanza, for example, hard, thorny /t/ alliteration ("Troubled," "travel-worn," "tangle") gives way to softer /h/ alliteration:
All heart-broke, I heard her say:
The breathy /h/ sounds evoke the ant's piteous tears—and the speaker's gentle "Pity[]" for her suffering.
In lines 15-16, meanwhile, intense /w/ alliteration draws attention to the glow-worm's speech:
Who replied, "What wailing wight
Calls the watchman of the night?
These moments of alliteration suggest the glow-worm's importance in the world of this poem: all those /w/ sounds ring out boldly, highlighting the glow-worm's words. In addition to the more closely packed /w/ alliteration in these lines, there is also spread-out /w/ alliteration (and consonance) in the lines before and after (such as "glow-worm" in line 14).
Finally, in the last two lines of the poem, /h/ alliteration feels both gentle and tidy:
Follow now the beetle's hum;
Little wanderer, hie thee home!
This alliteration makes the slant rhyme between "hum" and "home" stand out, making the phrase "hie thee home" feel like a memorable ending.