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

Helper for managing Thread in agent state.

Thread is stored at the reserved key `:__thread__` in `agent.state`.
This follows the same pattern as `:__strategy__` for strategy state.

## Example

    alias Jido.Thread.Agent, as: ThreadAgent

    # Ensure agent has a thread
    agent = ThreadAgent.ensure(agent, metadata: %{user_id: "u1"})

    # Append an entry
    agent = ThreadAgent.append(agent, %{kind: :message, payload: %{text: "hi"}})

    # Get the thread
    thread = ThreadAgent.get(agent)

# `append`

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

Append entry to agent's thread (ensures thread exists)

# `ensure`

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

Ensure agent has a thread (initialize if missing)

# `get`

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

Get thread from agent state

# `has_thread?`

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

Check if agent has a thread

# `key`

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

Returns the reserved key for thread storage

# `put`

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

Put thread into agent state

# `update`

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

Update thread using a function
