Jido.Agent.State (Jido v2.3.0)

Copy Markdown View Source

Internal helper module for agent state management.

Internal Module

This module is internal to the Agent implementation. Its API may change without notice.

Handles deep merging and validation of agent state.

Summary

Functions

Builds initial state from schema defaults.

Merges new attributes into existing state using deep merge semantics.

Validates state against a schema (NimbleOptions or Zoi). Returns validated state as a map.

Functions

defaults_from_schema(schema)

@spec defaults_from_schema(term()) :: map()

Builds initial state from schema defaults.

merge(current_state, attrs)

@spec merge(map(), map() | keyword()) :: map()

Merges new attributes into existing state using deep merge semantics.

validate(state, schema, opts \\ [])

@spec validate(map(), term(), keyword()) :: {:ok, map()} | {:error, term()}

Validates state against a schema (NimbleOptions or Zoi). Returns validated state as a map.

By default (non-strict mode), extra fields not in the schema are preserved. In strict mode, only schema-defined fields are kept.