Jido.Agent.StateOp (Jido v2.0.0-rc.1)

View Source

State operations that strategies handle to update agent state.

These are not directives - they never leave the strategy layer. They are separated from directives to maintain a clean boundary:

  • State operations → modify agent state within the strategy
  • Directives → external effects for the runtime to execute

Available State Operations

  • SetState - Deep merge attributes into state
  • ReplaceState - Replace state wholesale (no merge)
  • DeleteKeys - Remove top-level keys from state
  • SetPath - Set value at a nested path
  • DeletePath - Delete value at a nested path

Usage

Actions can return state operations alongside directives:

alias Jido.Agent.{Directive, StateOp}

{:ok, result, [
  %StateOp.SetState{attrs: %{status: :processing}},
  %Directive.Emit{signal: my_signal}
]}

The strategy applies state operations to the agent and passes through directives to the runtime.

Summary

Types

t()

Any state operation struct.

Functions

Creates a DeleteKeys state operation.

Creates a DeletePath state operation.

Creates a ReplaceState state operation.

Creates a SetPath state operation.

Creates a SetState state operation.

Types

Functions

delete_keys(keys)

@spec delete_keys([atom()]) :: Jido.Agent.StateOp.DeleteKeys.t()

Creates a DeleteKeys state operation.

delete_path(path)

@spec delete_path([atom()]) :: Jido.Agent.StateOp.DeletePath.t()

Creates a DeletePath state operation.

replace_state(state)

@spec replace_state(map()) :: Jido.Agent.StateOp.ReplaceState.t()

Creates a ReplaceState state operation.

set_path(path, value)

@spec set_path([atom()], term()) :: Jido.Agent.StateOp.SetPath.t()

Creates a SetPath state operation.

set_state(attrs)

@spec set_state(map()) :: Jido.Agent.StateOp.SetState.t()

Creates a SetState state operation.