Module Dsml.StreamSource

Streaming decode

Decode a completion as it is generated, token by token, emitting reasoning and content text as it arrives and tool calls once each block completes. This is the primitive an interactive agent feeds with model output.

Sourcetype event =
  1. | Reasoning of string
    (*

    a chunk of <think> reasoning

    *)
  2. | Content of string
    (*

    a chunk of reply text

    *)
  3. | Tool_call of tool_call
    (*

    a completed tool call

    *)
  4. | Done
    (*

    end of turn (EOS reached)

    *)

A piece of decoded output.

Sourcetype t

An incremental decoder.

Sourceval create : thinking_mode -> t

create mode is a fresh decoder.

Sourceval feed : t -> string -> event list

feed d chunk decodes the next chunk of generated text, in order. Partial markers spanning chunk boundaries are held back until complete.

Sourceval finish : t -> event list

finish d flushes buffered text at end of stream and emits Done.