Jido. BehaviorTree. Tick
(Jido Behavior Tree v1.0.0)
View Source
Represents a single execution cycle (tick) of a behavior tree.
A tick contains the context needed for a single traversal of the behavior tree, including the shared blackboard, timing information, and a sequence number for tracking execution order.
Ticks are immutable and are passed down through the tree during execution, allowing nodes to access shared state and timing information.
Summary
Functions
Appends directives to the tick's directive list.
Updates both agent and appends directives in one call.
Gets the elapsed time since the tick was created.
Gets a value from the tick's blackboard.
Increments the sequence number in the tick.
Creates a new tick with the given blackboard.
Creates a new tick with explicit parameters.
Creates a new tick with Jido agent context for strategy integration.
Sets a value in the tick's blackboard, returning an updated tick.
Returns the Zoi schema for this module
Checks if the tick has exceeded a timeout.
Updates a value in the tick's blackboard using a function.
Updates the agent in the tick.
Updates the blackboard in the tick.
Types
Functions
Appends directives to the tick's directive list.
Used by Action nodes to accumulate directives from Jido Effects.
Updates both agent and appends directives in one call.
Convenience function for Action nodes applying Jido Effects.
Gets the elapsed time since the tick was created.
Examples
iex> tick = Jido.BehaviorTree.Tick.new()
iex> Process.sleep(10)
iex> elapsed = Jido.BehaviorTree.Tick.elapsed_time(tick)
iex> elapsed > 0
true
Gets a value from the tick's blackboard.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123})
iex> tick = Jido.BehaviorTree.Tick.new(bb)
iex> Jido.BehaviorTree.Tick.get(tick, :user_id)
123
Increments the sequence number in the tick.
Examples
iex> tick = Jido.BehaviorTree.Tick.new()
iex> updated_tick = Jido.BehaviorTree.Tick.increment_sequence(tick)
iex> updated_tick.sequence
1
@spec new(Jido.BehaviorTree.Blackboard.t()) :: t()
Creates a new tick with the given blackboard.
The timestamp is set to the current time and sequence starts at 0.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{user_id: 123})
iex> tick = Jido.BehaviorTree.Tick.new(bb)
%Jido.BehaviorTree.Tick{blackboard: bb, sequence: 0}
@spec new(Jido.BehaviorTree.Blackboard.t(), DateTime.t(), non_neg_integer()) :: t()
Creates a new tick with explicit parameters.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new()
iex> now = DateTime.utc_now()
iex> tick = Jido.BehaviorTree.Tick.new(bb, now, 5)
%Jido.BehaviorTree.Tick{blackboard: bb, timestamp: now, sequence: 5}
@spec new_with_context(Jido.BehaviorTree.Blackboard.t(), term(), list(), map()) :: t()
Creates a new tick with Jido agent context for strategy integration.
This constructor is used by Jido.Agent.Strategy.BehaviorTree to pass
agent state and execution context through the tree during traversal.
Parameters
blackboard- The shared blackboardagent- The current Jido agent structdirectives- Initial list of directives (usually empty)context- Strategy execution context
Examples
tick = Tick.new_with_context(blackboard, agent, [], %{strategy_opts: opts})
Sets a value in the tick's blackboard, returning an updated tick.
Examples
iex> tick = Jido.BehaviorTree.Tick.new()
iex> updated_tick = Jido.BehaviorTree.Tick.put(tick, :result, "success")
iex> Jido.BehaviorTree.Tick.get(updated_tick, :result)
"success"
Returns the Zoi schema for this module
@spec timed_out?(t(), non_neg_integer()) :: boolean()
Checks if the tick has exceeded a timeout.
Examples
iex> tick = Jido.BehaviorTree.Tick.new()
iex> Jido.BehaviorTree.Tick.timed_out?(tick, 1000)
false
Updates a value in the tick's blackboard using a function.
Examples
iex> bb = Jido.BehaviorTree.Blackboard.new(%{counter: 5})
iex> tick = Jido.BehaviorTree.Tick.new(bb)
iex> updated_tick = Jido.BehaviorTree.Tick.update(tick, :counter, 0, &(&1 + 1))
iex> Jido.BehaviorTree.Tick.get(updated_tick, :counter)
6
Updates the agent in the tick.
Used by Action nodes to update agent state after executing Jido actions.
@spec update_blackboard(t(), Jido.BehaviorTree.Blackboard.t()) :: t()
Updates the blackboard in the tick.
Examples
iex> tick = Jido.BehaviorTree.Tick.new()
iex> new_bb = Jido.BehaviorTree.Blackboard.put(tick.blackboard, :result, "success")
iex> updated_tick = Jido.BehaviorTree.Tick.update_blackboard(tick, new_bb)
iex> Jido.BehaviorTree.Blackboard.get(updated_tick.blackboard, :result)
"success"