Jido.Agent.StateOps (Jido v2.3.0)

Copy Markdown View Source

Centralized state operation application for strategies.

Separates state operations (state mutations) from external directives. All strategies should use these helpers to ensure consistent behavior.

State Operation Types

  • StateOp.SetState - Deep merge attributes into state
  • StateOp.ReplaceState - Replace state wholesale
  • StateOp.DeleteKeys - Remove top-level keys
  • StateOp.SetPath - Set value at nested path
  • StateOp.DeletePath - Delete value at nested path

Any other struct is treated as an external directive and passed through.

Summary

Functions

Merges action result into agent state.

Applies a list of state operations to the agent.

Helper to put a value at a nested path, creating intermediate maps if needed.

Functions

apply_result(agent, result)

@spec apply_result(Jido.Agent.t(), map()) :: Jido.Agent.t()

Merges action result into agent state.

Uses deep merge semantics.

apply_state_ops(agent, effects)

@spec apply_state_ops(Jido.Agent.t(), [struct()]) :: {Jido.Agent.t(), [struct()]}

Applies a list of state operations to the agent.

State operations modify agent state. External directives are collected and returned for the runtime to process.

Returns {updated_agent, external_directives}.

deep_put_in(map, list, value)

@spec deep_put_in(map(), [atom()], term()) :: map()

Helper to put a value at a nested path, creating intermediate maps if needed.