High-performance asynchronous behavior tree framework with behavior forest collaboration,
Project description
๐ ABTree - Asynchronous Behavior Tree Framework
Asynchronous behavior tree framework built on Python asyncio, designed for intelligent decision systems
ไธญๆ | English
๐ Table of Contents
- โจ Core Features
- ๐ฌ Quick Start
- ๐ Documentation
- ๐ง Technology Stack
- ๐บ๏ธ Roadmap
- ๐ค Contributing
- ๐ License
โจ Core Features
| ๐ Async Engine | ๐ฏ Node System | ๐พ Data Management | ๐ฒ Behavior Forest |
|---|---|---|---|
| Based on asyncio High Performance Concurrency |
Rich Node Types Dynamic Registration |
Blackboard System Event Driven |
Multi-tree Collaboration Internal Communication Modes |
โก Asynchronous Behavior Tree Engine
- High Performance Async Execution - Concurrent node scheduling based on Python asyncio
- Smart Tick Management - Automated execution cycle management and resource control
- Event Driven Architecture - Asynchronous event system supporting real-time response
- Memory Optimization - Efficient state management and garbage collection
๐ฏ Rich Node System
- Composite Nodes - Sequence, Selector, Parallel and other classic control flows
- Decorator Nodes - Inverter, Repeater, UntilSuccess and other behavior modifiers
- Action Nodes - Action, Log, Wait, SetBlackboard and other execution units
- Condition Nodes - Condition, CheckBlackboard, Compare and other judgment logic
- Dynamic Registration - Runtime node type registration and extension mechanism
๐พ Smart Data Management
- Blackboard System - Cross-node data sharing and state persistence
- Event System - Asynchronous event listening, publishing and subscription mechanism
- State Management - Complete tracking of behavior tree execution state
- Data Validation - Type-safe data access and modification
๐ฒ Behavior Forest Collaboration
- Multi-tree Coordination - Multiple behavior trees working together as a forest
- Communication Modes - Pub/Sub, Req/Resp, Shared Blackboard, State Monitoring, Behavior Invocation, Task Board
- Forest Management - Centralized forest configuration and lifecycle management
- Performance Monitoring - Real-time performance analysis and optimization suggestions
๐ฌ Quick Start
๐ง Environment Setup
# Clone repository
git clone https://github.com/xiongwc/abtree.git
cd abtree
# Install dependencies
pip install -e .
๐ Basic Usage
๐ Method 1: Programmatic Building
import asyncio
from abtree import BehaviorTree, Sequence, Selector, Action, Condition
from abtree.core import Status
# Define action nodes
class OpenDoor(Action):
async def execute(self, blackboard):
print("Opening door")
return Status.SUCCESS
class CloseDoor(Action):
async def execute(self, blackboard):
print("Closing door")
return Status.SUCCESS
# Define condition nodes
class IsDoorOpen(Condition):
async def evaluate(self, blackboard):
return blackboard.get("door_open", False)
# Build behavior tree
root = Selector("Robot Decision")
root.add_child(Sequence("Door Control Sequence"))
root.children[0].add_child(IsDoorOpen("Check Door Status"))
root.children[0].add_child(CloseDoor("Close Door"))
# Create behavior tree instance
tree = BehaviorTree()
tree.load_from_node(root)
# Execute
async def main():
blackboard = tree.blackboard
blackboard.set("door_open", True)
result = await tree.tick()
print(f"Execution result: {result}")
asyncio.run(main())
๐ Method 2: XML Configuration
import asyncio
from abtree import load_from_xml_string
# Define XML string
xml_string = '''<BehaviorTree name="Robot Decision">
<Selector name="Robot Decision">
<Sequence name="Door Control Sequence">
<CheckBlackboard name="Check Door Status" key="door_open" expected_value="true" />
<Log name="Close Door Log" message="Door detected open, preparing to close" />
<Wait name="Close Door Wait" duration="1.0" />
</Sequence>
</Selector>
</BehaviorTree>'''
# Load behavior tree from XML string
tree = load_from_xml_string(xml_string)
# Execute
async def main():
blackboard = tree.blackboard
blackboard.set("door_open", True)
result = await tree.tick()
print(f"Execution result: {result}")
asyncio.run(main())
๐ฒ Behavior Forest Example
import asyncio
from abtree import (
BehaviorForest, ForestNode, ForestNodeType,
PubSubMiddleware, SharedBlackboardMiddleware,
BehaviorTree, Sequence, Selector, Action, Condition
)
from abtree.core import Status
# Simple robot action node
class RobotAction(Action):
def __init__(self, name: str, action_type: str):
super().__init__(name)
self.action_type = action_type
async def execute(self, blackboard):
print(f"Robot {self.action_type}")
if self.action_type == "cleaning":
blackboard.set("cleaning_needed", False)
return Status.SUCCESS
# Simple condition node
class SimpleCondition(Condition):
def __init__(self, name: str, key: str, default: bool = True):
super().__init__(name)
self.key = key
self.default = default
async def evaluate(self, blackboard):
return blackboard.get(self.key, self.default)
def create_robot_tree(robot_id: str) -> BehaviorTree:
"""Create a simple robot behavior tree"""
root = Selector(f"Robot_{robot_id}")
# Cleaning sequence
cleaning_seq = Sequence("Cleaning")
cleaning_seq.add_child(SimpleCondition("Check Cleaning", "cleaning_needed"))
cleaning_seq.add_child(RobotAction("Clean", "cleaning"))
cleaning_seq.add_child(RobotAction("Navigate", "navigating"))
root.add_child(cleaning_seq)
tree = BehaviorTree()
tree.load_from_node(root)
return tree
async def main():
# Create behavior forest
forest = BehaviorForest("Robot Forest")
# Add middleware
forest.add_middleware(PubSubMiddleware("PubSub"))
forest.add_middleware(SharedBlackboardMiddleware("Shared Blackboard"))
# Add robot nodes
for robot_id in ["R1", "R2", "R3"]:
tree = create_robot_tree(robot_id)
node = ForestNode(
name=f"Robot_{robot_id}",
tree=tree,
node_type=ForestNodeType.WORKER,
capabilities={"cleaning", "navigation"}
)
forest.add_node(node)
# Start forest
await forest.start()
# Execute ticks
for i in range(3):
results = await forest.tick()
print(f"Tick {i+1}: {results}")
await asyncio.sleep(0.5)
await forest.stop()
if __name__ == "__main__":
asyncio.run(main())
๐ Documentation
- ๐ Quick Start: examples/
- ๐ง API Reference: docs/api.md
- ๐ ๏ธ CLI Tools: cli/
- ๐งช Testing: tests/
๐ Project Structure
abtree/
โโโ abtree/ # ๐ฆ Core package
โ โโโ core/ # ๐ง Core functionality
โ โโโ engine/ # โ๏ธ Engine system
โ โโโ forest/ # ๐ฒ Behavior forest
โ โโโ nodes/ # ๐ฏ Node implementations
โ โโโ parser/ # ๐ Configuration parsing
โ โโโ registry/ # ๐ Node registration
โ โโโ utils/ # ๐ง Utilities
โโโ cli/ # ๐ฅ๏ธ Command line tools
โโโ docs/ # ๐ Documentation
โโโ examples/ # ๐ Example code
โโโ tests/ # ๐งช Test suite
โโโ scripts/ # ๐ Script tools
โโโ test_reports/ # ๐ Test reports
โโโ pyproject.toml # โ๏ธ Build and dependency configuration
๐ง Technology Stack
| Component | Technology | Version |
|---|---|---|
| Language | Python | 3.8+ |
| Async Framework | asyncio | Built-in |
| Data Validation | Pydantic | 2.0+ |
| XML Processing | xml.etree | Built-in |
| Testing | pytest | 7.0+ |
| Type Checking | mypy | 1.0+ |
๐ Code Standards
- Follow PEP 8 coding standards
- Use Google style docstrings
- Add type annotations for all functions
- Write unit tests for key functionality
๐บ๏ธ Roadmap
- โ v0.1 - Core asynchronous behavior tree framework
- โ v0.2 - XML configuration support
- โ v0.3 - Event system and blackboard optimization
- ๐ฏ v0.4 - Advanced node types
๐ค Contributing
- Fork the project repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
abtree-0.3.0.tar.gz
(70.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
abtree-0.3.0-py3-none-any.whl
(68.8 kB
view details)
File details
Details for the file abtree-0.3.0.tar.gz.
File metadata
- Download URL: abtree-0.3.0.tar.gz
- Upload date:
- Size: 70.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf89daa907490e583c22fbfc1615e99de51105644672c6fbc45a35e3c73976d
|
|
| MD5 |
e976834bc65f1ba248151ebce1b3ebca
|
|
| BLAKE2b-256 |
48d29656083a393b548fd2979c7cb441f40d5c915c37b4d7a2af88a19693a065
|
File details
Details for the file abtree-0.3.0-py3-none-any.whl.
File metadata
- Download URL: abtree-0.3.0-py3-none-any.whl
- Upload date:
- Size: 68.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5297b3d4c82146bd74f4731ef4049d904ddb0c9bbaeb53d6af0ced357bf0a552
|
|
| MD5 |
d3017ab1edfbd113100b22cc00bc570b
|
|
| BLAKE2b-256 |
c4a4ff2b69277e0fe9275209923d8dd08f58147918ee4e67029f3d1ae40673ab
|