generateStreamEvents

fun generateStreamEvents(model: String, messages: List<LlmMessage>, config: CompletionConfig = CompletionConfig(), correlationId: String? = null): Flow<CompletionStreamEvent>

Stream one turn as CompletionStreamEvents with terminal completion evidence.

Emits CompletionStreamEvent.Content events in order, then exactly one terminal event: CompletionStreamEvent.Completed when the provider reported a normal stop and ended the stream, or CompletionStreamEvent.Error otherwise. Truncated or unfinished output is an error, never a result; content received before an error is evidence only.

The turn sends one request with no tools, forces CompletionConfig.maxToolIterations to zero, and never retries. Stopping collection early cancels the request. A gateway that does not implement StreamEventsGateway yields a single StreamErrorReason.StreamEventsUnsupported error, with no request and no trace.

The call is traced when the request starts. The response, with the content received and the terminal evidence, is traced when the terminal event arrives. A consumer that stops early leaves a traced call and no traced response.

Parameters

model

Provider-side model identifier.

messages

Conversation history.

config

Completion knobs, including CompletionConfig.responseFormat.

correlationId

Correlation ID for tracer events; generated when null.