Jido. BehaviorTree. Skill
(Jido Behavior Tree v1.0.0)
View Source
A behavior tree skill that can be converted to AI-compatible tool definitions.
This module allows behavior trees to be exposed as skills that can be executed by AI systems. The behavior tree is wrapped in a skill interface that provides parameter validation, execution, and result formatting.
Features
- Convert behavior trees to LLM-compatible tool definitions
- Parameter validation and type checking
- Automatic blackboard management
- Execution result formatting
- Error handling and reporting
Example Usage
# Create a behavior tree
tree = Jido.BehaviorTree.Tree.new(root_node)
# Create a skill from the tree
skill = Jido.BehaviorTree.Skill.new(
"process_user_data",
tree,
"Processes user data through a behavior tree",
schema: [
user_id: [type: :integer, required: true],
data: [type: :map, required: true]
]
)
# Convert to tool format
tool_def = skill.to_tool()
# Execute the skill
{:ok, result} = skill.run(%{user_id: 123, data: %{name: "John"}}, %{})
Summary
Functions
Creates a new behavior tree skill.
Executes the behavior tree skill with the given parameters.
Returns the Zoi schema for this module
Converts the skill to an AI-compatible tool definition.
Types
Functions
@spec new(String.t(), Jido.BehaviorTree.Tree.t(), String.t(), keyword()) :: t()
Creates a new behavior tree skill.
Options
:schema- NimbleOptions schema for input validation (default: []):output_schema- NimbleOptions schema for output validation (default: []):timeout- Execution timeout in milliseconds (default: 30_000):auto_mode- Whether to run in automatic mode (default: false):interval- Tick interval for auto mode in milliseconds (default: 1000)
Examples
skill = Jido.BehaviorTree.Skill.new(
"data_processor",
tree,
"Processes data using behavior tree logic",
schema: [
input_data: [type: :map, required: true]
],
timeout: 10_000
)
Executes the behavior tree skill with the given parameters.
This function starts a behavior tree agent, executes the tree with the provided parameters in the blackboard, and returns the final result.
Parameters
params- Input parameters (will be validated against schema)context- Execution context (currently unused but reserved for future use)
Returns
{:ok, result}- Successful execution with result map{:error, reason}- Execution failed with error reason
Examples
{:ok, result} = Jido.BehaviorTree.Skill.run(skill, %{input_data: %{id: 1}}, %{})
Returns the Zoi schema for this module
Converts the skill to an AI-compatible tool definition.
Returns a map that can be used with LLM function calling systems like OpenAI's function calling.
Examples
tool_def = skill.to_tool()
# %{
# "name" => "data_processor",
# "description" => "Processes data using behavior tree logic",
# "parameters" => %{
# "type" => "object",
# "properties" => %{...},
# "required" => [...]
# }
# }