# `Jido.Memory.Agent`
[🔗](https://github.com/agentjido/jido/blob/v2.3.3/lib/jido/memory/agent.ex#L1)

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"})

# `append_to_space`

```elixir
@spec append_to_space(Jido.Agent.t(), atom(), term()) :: Jido.Agent.t()
```

Append an item to a list space.

# `delete_from_space`

```elixir
@spec delete_from_space(Jido.Agent.t(), atom(), term()) :: Jido.Agent.t()
```

Delete a key from a map space.

# `delete_space`

```elixir
@spec delete_space(Jido.Agent.t(), atom(), keyword()) :: Jido.Agent.t()
```

Delete a space. Raises on reserved spaces.

# `ensure`

```elixir
@spec ensure(
  Jido.Agent.t(),
  keyword()
) :: Jido.Agent.t()
```

Ensure agent has memory (initialize if missing).

# `ensure_space`

```elixir
@spec ensure_space(Jido.Agent.t(), atom(), map() | list()) :: Jido.Agent.t()
```

Ensure a space exists with default data. Does not overwrite existing.

# `get`

```elixir
@spec get(Jido.Agent.t(), Jido.Memory.t() | nil) :: Jido.Memory.t() | nil
```

Get memory from agent state.

# `get_in_space`

```elixir
@spec get_in_space(Jido.Agent.t(), atom(), term(), term()) :: term()
```

Get a key from a map space.

# `has_memory?`

```elixir
@spec has_memory?(Jido.Agent.t()) :: boolean()
```

Check if agent has memory.

# `has_space?`

```elixir
@spec has_space?(Jido.Agent.t(), atom()) :: boolean()
```

Check if a space exists.

# `key`

```elixir
@spec key() :: atom()
```

Returns the reserved key for memory storage.

# `put`

```elixir
@spec put(Jido.Agent.t(), Jido.Memory.t()) :: Jido.Agent.t()
```

Put memory into agent state.

# `put_in_space`

```elixir
@spec put_in_space(Jido.Agent.t(), atom(), term(), term()) :: Jido.Agent.t()
```

Put a key/value into a map space.

# `put_space`

```elixir
@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.

# `space`

```elixir
@spec space(Jido.Agent.t(), atom()) :: Jido.Memory.Space.t() | nil
```

Get a space by name.

# `spaces`

```elixir
@spec spaces(Jido.Agent.t()) :: map() | nil
```

Get the full spaces map.

# `update`

```elixir
@spec update(Jido.Agent.t(), (Jido.Memory.t() | nil -&gt; Jido.Memory.t())) ::
  Jido.Agent.t()
```

Update memory using a function.

# `update_space`

```elixir
@spec update_space(
  Jido.Agent.t(),
  atom(),
  (Jido.Memory.Space.t() -&gt; Jido.Memory.Space.t()),
  keyword()
) ::
  Jido.Agent.t()
```

Update a space using a function. Bumps both space and container revisions.
