pub enum Event {
ContentDelta {
id: String,
kind: ContentKind,
delta: String,
},
ContentFinal {
id: String,
kind: ContentKind,
content: String,
extensions: SegmentExtensions,
},
ToolCallStart {
id: Id,
name: Name,
},
ToolCallArgumentsDelta {
id: Id,
delta: Payload,
},
ToolCallFinal {
call: ToolCall,
extensions: SegmentExtensions,
},
Usage(TokenUsage),
Done {
finish_reason: String,
completion: CompletionReason,
provider_data: Vec<Envelope>,
},
}Expand description
One normalized event produced by a model provider adapter.
Deltas open an item identity and finals close it. Tool calls have an explicit
start/arguments/final lifecycle; StreamGrammar validates every pairing.
Deltas are optional. A provider that answers in one frame emits the final
alone, and the final’s payload is the whole item; see
StreamGrammar::accept. What a final may never do is contradict deltas
that were actually sent.
Variants§
ContentDelta
A fragment of one text or thinking item.
Fields
kind: ContentKindPortable content lane.
ContentFinal
The complete content and extensions for the same item.
Fields
kind: ContentKindContent lane, matching every delta.
content: StringThe whole item: the exact concatenation of all deltas, or, when no delta was sent, the content itself.
extensions: SegmentExtensionsProvider data owned by this final item.
ToolCallStart
Opens a client-local tool call.
A provider that delivers a call complete in one frame may omit this and
send only ToolCallFinal, which names the tool
itself.
ToolCallArgumentsDelta
Adds opaque argument bytes to the open tool call.
ToolCallFinal
Closes a tool call with the exact accumulated identity, name, and bytes.
When no argument delta preceded it, this event is the call: its identity, tool name and argument bytes are the whole of what reef records and what the executor receives.
Fields
extensions: SegmentExtensionsProvider data owned by this call.
Usage(TokenUsage)
Reports token accounting without changing item lifecycle.
§Usage is incremental, and normalising it is the adapter’s obligation
A generation may carry any number of these. Each one reports the tokens
consumed since the previous Usage of the same generation, so a
generation’s totals are the sum of its usage events, and one event
carrying the whole call’s totals is the ordinary single-increment case.
Reef does not and cannot check this. A provider that reports running totals and a provider that reports increments emit sequences core has no way to tell apart, so the rule is an obligation on the adapter rather than a grammar rule: an adapter for a provider that reports running totals must emit the difference, or withhold the numbers and emit one event at the end. An adapter that forwards running totals verbatim is not well-formed, and nothing will say so.
The rule is chosen because summation is the only operation available to
the consumer that receives these. They reach a hook through
ObserverHooks::model_event
and nowhere else, one event at a time, with no per-generation accumulator
of reef’s own to subtract from — so a budget policy adds them up. Under
the incremental rule that is exact at every scope: within a generation,
across the generations of a Run, and across Runs. Forwarded running
totals would double-count, and every budget built on them would fire
early.
Done
The single terminal event.
Trait Implementations§
Source§impl Debug for Event
impl Debug for Event
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
Keeps every identity and lane, and sizes the two content fields.
delta and content are the only members of this enum that own model
bytes directly. Everything else either identifies an item, classifies a
lane, counts tokens, or is a value that already redacts itself — and a
stream is debugged by its lifecycle, which those facts describe fully.