Jido.Memory.Agent
(Jido v2.0.0-rc.4)
View Source
Helper for managing Memory in agent state.
Memory is stored at the reserved key :__memory__ in agent.state.
This follows the same pattern as :__thread__ for thread state and
:__strategy__ for strategy state.
Provides generic space operations only. Domain-specific wrappers (world model, task lists, etc.) should be built in your own modules on top of these primitives.
Example
alias Jido.Memory.Agent, as: MemoryAgent
# Ensure agent has memory
agent = MemoryAgent.ensure(agent)
# Work with map spaces
agent = MemoryAgent.put_in_space(agent, :world, :temperature, 22)
temp = MemoryAgent.get_in_space(agent, :world, :temperature)
# Work with list spaces
agent = MemoryAgent.append_to_space(agent, :tasks, %{id: "t1", text: "Check sensor"})
Summary
Functions
Append an item to a list space.
Delete a key from a map space.
Delete a space. Raises on reserved spaces.
Ensure agent has memory (initialize if missing).
Ensure a space exists with default data. Does not overwrite existing.
Get memory from agent state.
Get a key from a map space.
Check if agent has memory.
Check if a space exists.
Returns the reserved key for memory storage.
Put memory into agent state.
Put a key/value into a map space.
Put a space by name. Bumps container rev and updated_at.
Get a space by name.
Get the full spaces map.
Update memory using a function.
Update a space using a function. Bumps both space and container revisions.
Functions
@spec append_to_space(Jido.Agent.t(), atom(), term()) :: Jido.Agent.t()
Append an item to a list space.
@spec delete_from_space(Jido.Agent.t(), atom(), term()) :: Jido.Agent.t()
Delete a key from a map space.
@spec delete_space(Jido.Agent.t(), atom(), keyword()) :: Jido.Agent.t()
Delete a space. Raises on reserved spaces.
@spec ensure( Jido.Agent.t(), keyword() ) :: Jido.Agent.t()
Ensure agent has memory (initialize if missing).
@spec ensure_space(Jido.Agent.t(), atom(), map() | list()) :: Jido.Agent.t()
Ensure a space exists with default data. Does not overwrite existing.
@spec get(Jido.Agent.t(), Jido.Memory.t() | nil) :: Jido.Memory.t() | nil
Get memory from agent state.
@spec get_in_space(Jido.Agent.t(), atom(), term(), term()) :: term()
Get a key from a map space.
@spec has_memory?(Jido.Agent.t()) :: boolean()
Check if agent has memory.
@spec has_space?(Jido.Agent.t(), atom()) :: boolean()
Check if a space exists.
@spec key() :: atom()
Returns the reserved key for memory storage.
@spec put(Jido.Agent.t(), Jido.Memory.t()) :: Jido.Agent.t()
Put memory into agent state.
@spec put_in_space(Jido.Agent.t(), atom(), term(), term()) :: Jido.Agent.t()
Put a key/value into a map space.
@spec put_space(Jido.Agent.t(), atom(), Jido.Memory.Space.t(), keyword()) :: Jido.Agent.t()
Put a space by name. Bumps container rev and updated_at.
@spec space(Jido.Agent.t(), atom()) :: Jido.Memory.Space.t() | nil
Get a space by name.
@spec spaces(Jido.Agent.t()) :: map() | nil
Get the full spaces map.
@spec update(Jido.Agent.t(), (Jido.Memory.t() | nil -> Jido.Memory.t())) :: Jido.Agent.t()
Update memory using a function.
@spec update_space( Jido.Agent.t(), atom(), (Jido.Memory.Space.t() -> Jido.Memory.Space.t()), keyword() ) :: Jido.Agent.t()
Update a space using a function. Bumps both space and container revisions.