Create self-referential data stream in kapacitor

I have a data stream and would like to use it to create another data stream if some condition exits, otherwise use the previous point from the ‘new’ data stream. Here is what I mean:

a_t = external data stream
b_t = f(a_t) if cond, b_(t-1) else

My problem is I don’t know how to ‘bootstrap’ this using tick script. I have a hunch this will require kapacitorLoopbackNode but I’m not sure exactly how this node works.

Any help would be much appreciated.