Encodes Elixir terms as JSON-safe values and back, without losing atoms, tuples, binaries, or ReqLLM structs.
Provider metadata on ReqLLM messages uses atom keys and values (for example
%{provider: :anthropic, signature: "..."}) that a JSON round trip would turn
into strings, which the provider encoders would then ignore. Values that JSON
can't represent are wrapped in a single-key object:
- atoms:
%{"$atom" => "anthropic"} - maps with atom keys:
%{"$atoms" => %{"provider" => ...}} - other maps with non-string keys:
%{"$map" => [[key, value], ...]} - tuples:
%{"$tuple" => [...]} - non-UTF-8 binaries:
%{"$binary" => base64} - ReqLLM structs:
%{"$struct" => "ReqLLM.Message", "fields" => ...}
Decoding only creates existing atoms and only rebuilds the ReqLLM structs listed here; any other value decodes to plain data.