关于 Behavior Trees
Behavior Trees 提供行为树验证、格式转换和编辑器链接生成,适用于使用 behavior3 JSON 或 BehaviorTree.CPP XML 的开发者。它可通过命令行或 MCP 客户端使用,生成的链接会在编辑器中打开树,且树内容不会上传。
主要功能
- 01验证行为树结构错误
- 02转换 JSON 与 XML 格式
- 03生成可编辑的编辑器链接
- 04列出节点类型并读取示例
- 05通过 CLI 和 JavaScript 库调用
适用场景
- 01在 CI 中检查行为树
- 02在两种行为树格式间转换
- 03将行为树分享给可视化编辑器
- 04让 AI 助手创建并检查行为树
MCP 相关
提供远程 Streamable HTTP MCP 服务,也可通过 stdio 本地运行。工具支持验证和转换行为树、创建编辑器链接、列出节点类型,以及读取示例和指南。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
https://www.behaviortrees.com/mcpclaude mcp add --transport http behaviortrees-behaviortrees https://www.behaviortrees.com/mcp{"mcpServers":{"behaviortrees-behaviortrees":{"type":"http","url":"https://www.behaviortrees.com/mcp"}}}在 Cursor 中打开{"servers":{"behaviortrees-behaviortrees":{"type":"http","url":"https://www.behaviortrees.com/mcp"}}}在 VS Code 中打开{"mcpServers":{"behaviortrees-behaviortrees":{"type":"http","url":"https://www.behaviortrees.com/mcp"}}}{"mcpServers":{"behaviortrees-behaviortrees":{"serverUrl":"https://www.behaviortrees.com/mcp"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
详细介绍
behaviortrees
从命令行或任何 MCP 客户端验证、转换和分享行为树。它使用与 behaviortrees.com 上的免费可视化编辑器相同的代码,因此它接受的内容,编辑器也能打开。
- 验证 behavior3 JSON 和 BehaviorTree.CPP XML:悬空子节点、拥有两个父节点的节点、循环、子节点多于一个的装饰器、带有子节点的叶节点、未知节点名称。
- 转换 behavior3 JSON 和 BehaviorTree.CPP XML(适用于 ROS 2 Jazzy 和 Groot2 的 v4,适用于 ROS 2 Humble 的 v3)。
- 链接:将行为树转换为可在编辑器中打开的 URL,并自动布局且可编辑。行为树包含在链接中,因此不会上传任何内容。
CLI
npx behaviortrees validate tree.json
npx behaviortrees convert tree.json --to btcpp-v4 -o tree.xml
npx behaviortrees convert nav2_tree.xml --to behavior3
npx behaviortrees link tree.json --open
npx behaviortrees nodes # built-in node types
npx behaviortrees examples # example trees; add an id to print one
npx behaviortrees guides # behaviortrees.com guides; add a slug to read one
省略文件或传入 -,即可从 stdin 读取。--json 会输出机器可读的结果;validate 在行为树存在错误时以状态码 1 退出,因此可用于 CI。
MCP 服务
让 AI 助手编写行为树、检查行为树,并提供一个可在编辑器中打开的链接。工具:validate_tree、create_editor_link、convert_tree、list_node_types、get_example、read_guide。
远程服务,无需安装(Streamable HTTP):
https://www.behaviortrees.com/mcp
或者通过 stdio 在本地运行:
{
"mcpServers": {
"behaviortrees": { "command": "npx", "args": ["-y", "behaviortrees", "mcp"] }
}
}
对于 Claude Code:claude mcp add --transport http behaviortrees https://www.behaviortrees.com/mcp
行为树格式
一个最简的 behavior3 行为树。位置为可选项;编辑器会自动布局行为树。
{
"title": "Guard",
"root": "a",
"nodes": {
"a": { "name": "Priority", "children": ["b", "c"] },
"b": { "name": "Sequence", "children": ["d", "e"] },
"c": { "name": "Patrol" },
"d": { "name": "IsEnemyVisible" },
"e": { "name": "Attack" }
},
"custom_nodes": [
{ "name": "IsEnemyVisible", "category": "condition" },
{ "name": "Attack", "category": "action" },
{ "name": "Patrol", "category": "action" }
]
}
复合节点按运行顺序在 children 中列出子节点,装饰器有一个 child,其他节点都是叶节点。Priority 是 behavior3 中的选择器(回退)。任何非内置节点都要在 custom_nodes 下声明。
库
import { validateTree, convertTree, createEditorLink } from 'behaviortrees';
const { valid, findings } = await validateTree(json);
const { output } = await convertTree(json, 'btcpp-v4');
const { url } = await createEditorLink(json);
许可证
AGPL-3.0-only(见 LICENSE)。部分内容源自 Renato de Pontes Pereira 采用 MIT 许可的 behavior3editor(见 LICENSE-MIT)。源码:github.com/behaviortrees/behaviortrees。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。