Sycophant.WireProtocol behaviour (sycophant v0.4.2)

Copy Markdown

Behaviour for chat wire protocol adapters.

Wire protocol adapters encode Sycophant.Request structs into provider-specific JSON payloads and decode provider responses back into Sycophant.Response structs. Dispatch is by wire protocol metadata from LLMDB, not by provider identity.

Built-in Adapters

Summary

Callbacks

decode_response(map)

@callback decode_response(map()) ::
  {:ok, Sycophant.Response.t()} | {:error, Splode.Error.t()}

decode_stream_chunk(state, event)

@callback decode_stream_chunk(state :: term(), event :: map()) ::
  {:ok, term(), [Sycophant.StreamChunk.t()]}
  | {:done, Sycophant.Response.t()}
  | {:done, Sycophant.Response.t(), [Sycophant.StreamChunk.t()]}
  | {:terminate, :failed | :incomplete | :cancelled, Splode.Error.t()}
  | {:error, Splode.Error.t()}

encode_request(t)

@callback encode_request(Sycophant.Request.t()) ::
  {:ok, map()} | {:error, Splode.Error.t()}

encode_response_schema(map)

@callback encode_response_schema(map()) :: {:ok, map()} | {:error, Splode.Error.t()}

encode_tools(list)

@callback encode_tools([Sycophant.Tool.t()]) ::
  {:ok, [map()]} | {:error, Splode.Error.t()}

init_stream()

@callback init_stream() :: term()

param_schema()

@callback param_schema() :: Zoi.schema()

request_path(t)

@callback request_path(Sycophant.Request.t()) :: String.t()

stream_transport()

(optional)
@callback stream_transport() :: :sse | :event_stream