# `ExAthena.Loop.Terminations`
[🔗](https://github.com/udin-io/ex_athena/blob/v0.7.1/lib/ex_athena/loop/terminations.ex#L1)

Typed termination subtypes for agent-loop runs.

Every run ends with exactly one termination. Normal completions use `:stop`;
everything else is an error subtype carrying enough context (usage, cost,
duration) to drive retries and observability.

Inspired by the Claude Agent SDK's typed termination subtypes — they keep
accounting uniform across happy and sad paths.

## Subtypes

  * `:stop` — model returned text with no tool calls.
  * `:error_max_turns` — iteration cap reached.
  * `:error_max_budget_usd` — cost ceiling tripped.
  * `:error_during_execution` — unrecoverable tool / provider error.
  * `:error_max_structured_output_retries` — repair budget exhausted.
  * `:error_consecutive_mistakes` — mistake counter threshold hit.
  * `:error_halted` — hook or tool returned `:halt`.
  * `:error_compaction_failed` — context compaction failed.
  * `:error_prompt_too_long` — provider rejected the request because the
    assembled prompt exceeded the model's context window. Modes signal this
    to the kernel so the compaction pipeline can attempt reactive recovery
    before the run terminates.

# `subtype`

```elixir
@type subtype() ::
  :stop
  | :error_max_turns
  | :error_max_budget_usd
  | :error_during_execution
  | :error_max_structured_output_retries
  | :error_consecutive_mistakes
  | :error_halted
  | :error_compaction_failed
  | :error_prompt_too_long
```

# `all`

```elixir
@spec all() :: [subtype()]
```

All known termination subtypes.

# `category`

```elixir
@spec category(subtype()) :: :success | :retryable | :capacity | :fatal
```

Categorise a termination for retry classification. Returns one of:
`:retryable`, `:capacity`, `:fatal`.

  * `:retryable` — transient; caller may retry on a new run.
  * `:capacity` — the run hit a configured limit; caller should increase
    the limit or reduce scope.
  * `:fatal` — don't retry without operator action.

# `error?`

```elixir
@spec error?(subtype()) :: boolean()
```

Is this an error termination?

# `success?`

```elixir
@spec success?(subtype()) :: boolean()
```

Is this a successful termination?

---

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