Jido.Agent.StateBudget (Jido v2.4.0)

Copy Markdown View Source

Enforces an optional byte budget for the complete agent state.

The size is the external term size from :erlang.external_size/1. It is not the BEAM heap size. A nil limit disables the size calculation.

Summary

Functions

Checks the full state and returns the agent or a structured error.

Checks the state, raising a validation error if the budget is exceeded.

Returns the effective state budget, including the agent module's limit.

Replaces the state or returns a structured budget error.

Replaces the state, raising a validation error if the budget is exceeded.

Checks a proposed replacement while retaining the previous budget.

Types

result()

@type result() :: {:ok, Jido.Agent.t()} | {:error, Jido.Error.ValidationError.t()}

Functions

check(agent)

@spec check(Jido.Agent.t()) :: result()

Checks the full state and returns the agent or a structured error.

check!(agent)

@spec check!(Jido.Agent.t()) :: Jido.Agent.t()

Checks the state, raising a validation error if the budget is exceeded.

limit(agent)

@spec limit(Jido.Agent.t()) :: non_neg_integer() | nil

Returns the effective state budget, including the agent module's limit.

replace(agent, state)

@spec replace(Jido.Agent.t(), map()) :: result()

Replaces the state or returns a structured budget error.

replace!(agent, state)

@spec replace!(Jido.Agent.t(), map()) :: Jido.Agent.t()

Replaces the state, raising a validation error if the budget is exceeded.

transition(previous, candidate)

@spec transition(Jido.Agent.t(), Jido.Agent.t()) :: result()

Checks a proposed replacement while retaining the previous budget.