It's quite difficult to write in TensorFlow and will often have you staring at the API for the right functions. You have to convert the recursion into the form of a while loop and then invoke
One comparison that might be helpful are the following two examples (, ). They implement sampling from a Geometric distribution by drawing Bernoulli trials until one lands heads. One uses naive recursion, which fails in TensorFlow. The other uses a stochastic while loop, which works.
Another place to get started is to postpone work on the tree-building altogether. Instead, first work on adapting the step size via Nesterov's dual averaging, and adaptation to find a good initial step size. These are much easier to make progress on.
(No worries; this is the right place for development discussion.)