# `MingaAgent.Branch`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_agent/branch.ex#L1)

Conversation branching for the agent session.

Allows rewinding to an earlier turn and trying a different prompt,
creating a branch. Previous branches are preserved and can be revisited.
This enables "what if" exploration without losing prior work.

# `t`

```elixir
@type t() :: %MingaAgent.Branch{
  created_at: DateTime.t(),
  messages: [MingaAgent.Message.t()],
  name: String.t()
}
```

A named conversation branch.

# `branch_at`

```elixir
@spec branch_at([MingaAgent.Message.t()], non_neg_integer(), String.t(), [t()]) ::
  {:ok, [MingaAgent.Message.t()], [t()]} | {:error, String.t()}
```

Branches at the given turn index, saving the current messages
as a named branch and returning the truncated message list.

Turn index is 0-based. Messages from index 0 to `turn_index` (inclusive)
are kept; the rest become the branch.

# `list`

```elixir
@spec list([t()]) :: String.t()
```

Lists all branches with their names and message counts.

# `new`

```elixir
@spec new(String.t(), [MingaAgent.Message.t()]) :: t()
```

Creates a new branch from the given messages.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
