after doing res, err := gw.Solve() you should be able to use a ref from that result inside a future LLB request.
For implementation, every ref returned should be associated with the edge digest that pointed to it. Now when this is used in LLB it should just marshal into the same digest without the actual definition and when doing a next solve solver will just pick up the old vertex from the graph.
A similar technique is used in llb-gobuild https://github.com/tonistiigi/llb-gobuild/blob/e8a5c93b8173ed02dd82be319006598fa9c52acf/cmd/gobuild/main.go#L123-L134
@ijc