Skip to content
Tech News
← Back to articles

Show HN: Go-Bt: Minimalist Behavior Trees for Go

read original get Behavior Tree Go Kit → more articles
Why This Matters

go-bt introduces a minimalist and stateless behavior tree library for Go, optimized for background workers, game AI, and automation tasks. Its design emphasizes cooperative multitasking, native context integration, and testability, making it a powerful tool for reliable and efficient asynchronous logic implementation in the Go ecosystem.

Key Takeaways

go-bt: Minimalist Behavior Trees for Go

go-bt is a Behavior Tree library for Go.

Designed for background workers, game AI, mundane task automation, and asynchronous logic.

Instead of time.Sleep or infinite while loops, go-bt uses a cooperative multitasking model. Nodes return state instantly, yielding control back to the supervisor.

Core Design Principles

Stateless Nodes: Nodes ( Sequence , Selector , etc.) do not hold runtime state. All temporal memory and execution states live entirely within the generic BTContext[T] . The Magic Numbers: Every node's Run method returns exactly one of three integers: 1 ( Success ): The task is done and successful.

( ): The task is done and successful. 0 ( Running ): The task needs more time (e.g., waiting on I/O, or sleeping). It yields the thread.

( ): The task needs more time (e.g., waiting on I/O, or sleeping). It yields the thread. -1 (Failure): The task failed. First-Class Context: BTContext[T] directly embeds Go's standard context.Context , ensuring your trees natively respect global cancellation tokens and timeouts. Time-Travel Testing: The engine uses an injected clock directly on the context, allowing you to instantly test a 5-minute Timeout or Sleep node in your unit tests without actually waiting.

The Node Library

go-bt provides a minimalist set of core nodes that can be combined to create any logical control flow:

... continue reading