Go-Bt: Minimalist Behavior Trees for Go

What it is
Go-bt is a compact Behavior Tree library for Go, published on GitHub. It has been reported that the project is aimed at background workers, game AI, mundane task automation and other asynchronous logic — basically anywhere you’d otherwise reach for time.Sleep or an infinite loop. It takes a cooperative multitasking approach: nodes return a state immediately and yield control back to a supervisor, rather than blocking goroutines.
How it works
The engine leans on a few tight design decisions. Nodes are stateless; all runtime memory lives in a generic BTContext[T] that embeds Go’s standard context.Context, so cancellations and deadlines are first-class. Each node’s Run method returns exactly one of three integers — 1 for Success, 0 for Running, -1 for Failure — a simple contract that keeps the execution model explicit and tiny. Testing gets a nice trick too: the context accepts an injected clock, allowing “time-travel” tests where you can simulate a 5‑minute timeout instantly. Tired of waiting on timers in CI? This is why.
Nodes and usage
The library ships a minimalist node library: composites (Selector, Sequence, MemSequence), decorators (Inverter, Timeout, Retry), and leaves (Condition, Action, Sleep). It uses Go generics for the blackboard type — your state can be any struct — and includes a panic-safe Supervisor that ticks a tree at a configured interval and returns a WaitGroup for shutdown coordination. The README includes a small worker example that connects, processes tasks, and cancels a parent context when done. Short, practical, and focused. Your CI might actually thank you.
Why it matters
Why should Go developers care? Because go-bt trades heavyweight frameworks and blocking sleeps for a tiny, composable control-flow primitive that plays nicely with Go’s context and testing practices. It’s opinionated and minimalist — not trying to be everything. That will appeal to engineers who prefer small, well-scoped tools over monoliths. The project’s Hacker News thread generated discussion and examples; if you like clear primitives and fast, testable timing, this one’s worth a look.
Sources: github.com/rvitorper, Hacker News
Comments