This sentence is object omission.
This sentence is from "Those who seek hermitage are not found" by Jia Dao, a poet of the Tang Dynasty. In this poem, there is indeed the phenomenon of object omission. According to the grammatical rules of modern Chinese, the complete sentence should be "I" asked the boy "Tongzi" said the teacher to collect medicine."
But in this poem, the expressions of "I" and "Tongzi" Being omitted makes the poem more concise and implicit, leaving more room for the reader's imagination. This omission is relatively common in ancient poetry, mainly to pursue the rhythm and simplicity of poetry.