I don’t think there is a way to do this, if I am understanding your question correctly. At the low level, Bokeh legends can accept two kinds of things: value or field:
from bokeh.core.properties import value, field
# Creates a single legend row, labeled "foo"
p.multi_line(..., legend=value("foo"))
# Does a "groupby" on a CDS column "foo" and creates multiple legend rows
p.multi_line(..., legend=field("foo"))
As a last observation, Bokeh does a little auto-detecting if you are not explicit. If you just pass legend="foo" then Bokeh will interpret that you wanted field("foo") if a column “foo” exists in the glyph’s data source. Otherwise it interprets as value("foo") if no such column is present.
If I understand your meaning, you want to somehow mix these two modes? That is not possible at present. I think you will need to construct a value(...) for every row you want in the legend up front, with exactly the text you want to see in each row (i.e. you will have to do any “groupby” yourself on the python side)