Jido.BehaviorTree.Nodes.Action (Jido Behavior Tree v1.0.0)

View Source

A leaf node that executes a Jido Action.

The Action node wraps a Jido Action module and executes it when ticked. The action result is converted to behavior tree statuses:

  • {:ok, result} -> :success
  • {:error, reason} -> {:error, reason}

Parameters are passed to the action and can include values from the blackboard.

Example

action = Action.new(MyApp.Actions.SendEmail, %{
  to: "user@example.com",
  subject: "Hello"
})

Using Blackboard Values

You can reference blackboard values using the :from_blackboard option:

action = Action.new(MyApp.Actions.ProcessData, %{
  data: {:from_blackboard, :input_data}
})

Summary

Functions

Creates a new Action node for the given action module.

Returns the Zoi schema for this module

Context-aware tick that integrates with Jido Agent Effects.

Types

t()

@type t() :: %Jido.BehaviorTree.Nodes.Action{
  action_module: any(),
  context: any(),
  params: any(),
  result: nil | any()
}

Functions

new(action_module, params \\ %{}, context \\ %{})

@spec new(module(), map(), map()) :: t()

Creates a new Action node for the given action module.

Parameters

  • action_module - The Jido Action module to execute
  • params - Parameters to pass to the action (default: %{})
  • context - Context to pass to the action (default: %{})

Examples

iex> Action.new(MyAction)
%Action{action_module: MyAction, params: %{}, context: %{}}

iex> Action.new(MyAction, %{input: "value"})
%Action{action_module: MyAction, params: %{input: "value"}, context: %{}}

schema()

Returns the Zoi schema for this module

tick_with_context(state, tick)

Context-aware tick that integrates with Jido Agent Effects.

When called via Tree.tick_with_context/2, this function:

  1. Resolves params from the blackboard
  2. Builds a Jido Instruction with agent state context
  3. Executes via Jido.Exec.run/1
  4. Applies results and effects to the agent via Jido.Agent.Effects
  5. Accumulates directives on the tick
  6. Updates the blackboard with last_result

Returns a 3-tuple {status, updated_node, updated_tick}.