Asynchronous Behaviour Trees

Behaviour Tree is a technique widely used in game industry and robotics. It is so popular, because it helps people understand complex algorithms. With a proper tooling (Visual Editors), those people don’t even have to be programmers. In fact, in game industry, the trees are assembled by game designers. The programmers are only needed to implement new types of nodes.

If you are interested in an in depth explanation of the topic. Please have a look at following article, which explains the use of behaviour trees in the game industry

For usage in robotics and a more formal definition, please have a look here

If you are more of a tl;dr person, behaviour trees are like uni directional data flow thing. Like console pipe for AI. 😎

Now seriously, just read the articles.

I hope you read those articles…

Back to main topic — Asynchronous Behaviour Trees

In robotics and games, behaviour trees are executed synchronously on every tick. I had the crazy idea, to use behaviour tree in context of a web application. Imagine you have a web endpoint which is not a basic CRUD, but builds up a response based on a complex context. A response where we have to execute multiple queries, aggregate the data and sacrifice a virgin.

To keep such endpoint maintainable and extendable, we could represent the logic behind such endpoint as a behaviour tree. It helps game designers and robot developers stay sane. And boy those guys know, what it means to maintain a highly complex algorithms.

However here is the trick. The typical behaviour trees from robotics and games are synchronous, as in those fields, the behaviour has to be real time. This is why the data your nodes suppose to work with are already under your finger tips.

In case of a web application, we don’t have to be real time. As a matter of fact, we would like to make some queries to data base, or maybe even another web services. This queries take time and it would be fine just to get a callback when those long running tasks are done.

This is where the idea of asynchronous behaviour trees came to me. The main difference is that nodes don’t return there state, there parent pass them a callback, which they call, when they are done. It also implies that we don’t need the Running state any more.

I am looking into implementing a reference implementation in Swift and JavaScript and it helps my motivation if people show interest. So if it does interest you, drop me a line, comment here, or just like this article.

Thanks for reading!!!

Show your support

Clapping shows how much you appreciated Maxim Zaks’s story.