Sycophant.Serializable protocol (sycophant v0.4.2)

Copy Markdown

Protocol for converting Sycophant structs to plain maps for JSON serialization.

Every implementation includes a "__type__" discriminator key that enables round-trip decoding via Sycophant.Serializable.Decoder.

Round-trip Example

response = %Sycophant.Response{...}
json = Sycophant.Serializable.Decoder.encode(response)
restored = Sycophant.Serializable.Decoder.decode(json)

All core structs implement this protocol: Response, Context, Message, Tool, ToolCall, Usage, Reasoning, EmbeddingRequest, EmbeddingResponse, EmbeddingParams, and content parts.

Summary

Types

t()

All the types that implement this protocol.

Functions

Converts a Sycophant struct into a plain map with a __type__ discriminator.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

to_map(struct)

@spec to_map(t()) :: map()

Converts a Sycophant struct into a plain map with a __type__ discriminator.