# `ExGAM.Mind`
[🔗](https://github.com/elchemista/ex_gam/blob/0.1.0/lib/ex_gam/mind.ex#L1)

Capability-free boundary for application deliberation.

A mind may route, plan, call application code and construct Candidates.  It
receives no Grant, broker or ledger writer, and its result remains only a
proposal until each Candidate independently crosses the kernel boundary.

`use ExGAM.Mind, ref: "mind:my-app:v1"` declares the behaviour and an
overridable `c:ref/0`. Implement `c:deliberate/2` yourself. When this stateless
implementation is used by an Instance, the existing runtime bridge preserves
its local state unchanged.

For a stateful implementation, opt into `stateful: true` and implement
`c:deliberate/3`. The generated, overridable `c:deliberate/2` calls it with `nil`
state and discards the returned state. A stateless call therefore starts
without local state; it never substitutes the options for that state. Your
callback must handle `nil` or you must override `c:deliberate/2` explicitly.

This helper does not choose an Agent, flow, router, pipeline or fallback,
record derived Evidence, or submit Candidates. Those remain application
decisions. Plain `@behaviour ExGAM.Mind` implementations remain supported.

Without the helper, `c:deliberate/2` is always required; `c:deliberate/3` is an
optional, explicit stateful variant. Define both arities separately. Do not
write `def deliberate(turn, state, opts \ [])`: the generated `/2` would
receive stateless turn options as `state`. The two callbacks also have
intentionally different success shapes:

    def deliberate(turn, opts), do: {:ok, candidates(turn, opts)}

    def deliberate(turn, state, opts) do
      {:ok, candidates(turn, opts), next_state(state)}
    end

# `deliberate`

```elixir
@callback deliberate(ExGAM.Mind.Turn.t(), keyword()) ::
  {:ok,
   ExGAM.Candidate.t()
   | map()
   | keyword()
   | [ExGAM.Candidate.t() | map() | keyword()]}
  | {:error, term()}
```

Produces Candidate proposals from a sealed Turn and deliberation options.

# `deliberate`
*optional* 

```elixir
@callback deliberate(ExGAM.Mind.Turn.t(), term(), keyword()) ::
  {:ok,
   ExGAM.Candidate.t()
   | map()
   | keyword()
   | [ExGAM.Candidate.t() | map() | keyword()], term()}
  | {:error, term()}
```

Produces Candidate proposals and the adapter's next application state.

# `ref`

```elixir
@callback ref() :: String.t()
```

Returns the stable identifier of this deliberation adapter.

# `candidate`

```elixir
@spec candidate(ExGAM.Mind.Turn.t(), map() | keyword()) ::
  {:ok, ExGAM.Candidate.t()} | {:error, term()}
```

Builds a Candidate whose trusted proposer and Scope come from the sealed Turn.

# `candidate`

```elixir
@spec candidate(
  ExGAM.Mind.Turn.t(),
  ExGAM.Evidence.t() | [ExGAM.Evidence.t()],
  map() | keyword()
) ::
  {:ok, ExGAM.Candidate.t()} | {:error, term()}
```

Builds a Candidate that may also cite validated derivations produced from the same Turn.

# `deliberate`

```elixir
@spec deliberate(module(), ExGAM.Mind.Turn.t(), keyword()) ::
  {:ok, [ExGAM.Candidate.t()]} | {:error, term()}
```

Invokes a mind and normalizes its output to scope-bound Candidates.

# `deliberate`

```elixir
@spec deliberate(module(), ExGAM.Mind.Turn.t(), term(), keyword()) ::
  {:ok, [ExGAM.Candidate.t()], term()} | {:error, term()}
```

Invokes an optional stateful Mind callback without making its state authoritative.

# `evidence`

```elixir
@spec evidence(ExGAM.Mind.Turn.t(), integer(), map() | keyword()) ::
  {:ok, ExGAM.Evidence.t()} | {:error, term()}
```

Builds derived or generated Evidence bound to the exact sealed Turn context.

---

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