Skip to main content

misbehave

Misbehave is a Python behavior tree implementation. A behavior tree is a design pattern that breaks complex state-based actions into their component parts to improve readability and re-usability for autonomous agents. A good starting place to understand them is here.

Misbehave focused on python language features not available in other languages, so some of the common features of AI design are missing by default. The rest of this document is lightly hedged in its language as behavior trees can be useful for video games or robots.

How to use Misbehave

A node in a Misbehave behavior tree is simply a callable. While the ones provided with this library are classes, you can use functions or closures to define them.

The signature of a node's function is simple:

def MyNode(actor: Any, context: Any) -> misbehave.State
    # Perform actions here.

An actor is an object representing the thing the behavior tree is controlling. In a video game, this would be the mob object.

The context is available for providing access to things like sensors, controls, other code objects representing things in space. If you don't need them, you can pass None here.

An example of a tree might look like this in your code:

class MyActor():
    tree = misbehave.selector.Sequence(
        misbehave.action.IncreaseValue("behavior_tree_runs"),
        my_actions.MoveForward(10),
        my_actions.Rotate(90)
    )
    behavior_tree_runs = 0

This simple tree keeps track of how many times the entire tree was run, and then moves the actor in a square. You must implement the specifics of the actions here.

Development

Misbehave requires Python 3.6 or later.

To work on misbehave, after forking and cloning locally, you'll want to setup a virtual environment. You'll notice we don't have any requirement files: all requirements are listed in setup.cfg either as setup_requires or as extras.

In your project directory, with your virtual environment active:

python -m pip install -e .[dev, tests]

If you do not do an editable install of misbehave, misbehave.version will be missing and the library will fail to work.

Other than that, we are ready for PEP 518 and 517, so if you're using a build tool that supports them, feel free!

It is strongly encouraged that you run black on the misbehave directory and then pytest before commiting to any working branch. Failure to lint will disqualify a PR.

Metadata

Release files for misbehave 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for misbehave 0.1.4
File Size Uploaded
misbehave-0.1.4.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for misbehave 0.1.4
File Interpreter ABI Platform
misbehave-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / misbehave-0.1.4.tar.gz

Download URL misbehave-0.1.4.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
41dee958be68340f3cdf92598880bcab6cd52bfdb63b58e30014a3e9dccffd37
BLAKE2b-256 checksum
How to use checksums
0a04acee43e01f49c7440fbbed9afe4b68bdd903580780f25388b64db67df4f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / misbehave-0.1.4-py3-none-any.whl

Download URL misbehave-0.1.4-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5a4e1bcacb1a727d9bfa88363f5a90769332afa1ee9c1aed780ff57e14fe935
BLAKE2b-256 checksum
How to use checksums
97dac1ba8241b9b0f89d88fa02764677e3af8bd93bee781cf3cb9c838b04801d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page