# `Imp.History`
[🔗](https://github.com/deepfates/imp/blob/v0.18.1/lib/imp/history.ex#L1)

Immutable conversation history for signature-shaped Imp programs.

A history is a sequence of prior task turns keyed by the same fields as the
signature, not raw chat messages. For a signature like
`"question, history -> answer"`, a turn can be
`%{question: "Capital of France?", answer: "Paris"}`. Turns are normalized
through `Imp.Example`, so a turn must be a field map or a list of field pairs.

The Chat adapter renders each turn as prior user/assistant messages by
splitting the fields according to the active signature, which keeps a history
serializable and independent of any one provider's chat message schema.
A turn may also carry `:user_name` and `:assistant_name` to give its
messages a participant name; see "Naming messages" in `Imp.Adapter.Chat`.

    iex> history =
    ...>   Imp.History.new()
    ...>   |> Imp.History.append(%{question: "Capital of France?", answer: "Paris"})
    iex> Imp.History.messages(history)
    [%{answer: "Paris", question: "Capital of France?"}]

# `field_key`

```elixir
@type field_key() :: atom() | String.t()
```

# `t`

```elixir
@type t() :: %Imp.History{messages: [turn()]}
```

# `turn`

```elixir
@type turn() :: %{optional(field_key()) =&gt; term()}
```

# `append`

Appends one signature-shaped history turn.

# `dump`

Dumps history to a JSON-safe map.

# `load!`

Loads a JSON-safe history map produced by `dump/1`.

Existing atoms and typed values are preserved. Loading never creates atoms: a
symbolic atom whose owning capability is not loaded becomes its exact name as
a string, so earlier turns stay usable after a restart or a capability
removal. Dumping the loaded history records that string representation.

Malformed tags and map-key collisions introduced by this conversion are
rejected, and a state without a list `"messages"` raises `ArgumentError`.

# `messages`

Returns the signature-shaped field maps in insertion order.

# `new`

Builds history from a list of signature-shaped field maps.

# `redact`

Redacts secret-looking values while preserving history structure.

---

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