Streaming
SemanticEvent streaming — yield provider chunks from inference and handle them with onInternalEvent and onExternalEvent.
Streaming is how SemanticEvent<T> moves through the environment. Alongside messages (string) and ContextItems (completed model/tool artifacts), semantic events are the third exchangeable event kind: incremental provider payloads with a type and data, delivered while inference is still running.
When streaming is enabled, inference yields SemanticEvent instances as the provider emits chunks, and the environment delivers each one on the bus — onInternalEvent on the producer, onExternalEvent(source, event) on everyone else.
Enable streaming
Pass streaming: true to runInference for a model whose specification supports it:
runInference({ model: 'gpt-5.5', context, caller: this, environment, streaming: true });Each yielded event is a SemanticEvent<T> — event.type names the provider event, event.data carries the payload. Use the handlers to drive a live UI — for example, print text deltas from response.output_text.delta events:
import { BaseParticipant, Participant, SemanticEvent } from '@mozaik-ai/core';
export class LiveUIAgent extends BaseParticipant {
// Observe this agent's own stream chunks.
async onInternalEvent(event: SemanticEvent<unknown>): Promise<void> {
if (event.type === 'response.output_text.delta') {
process.stdout.write(String((event.data as { delta?: string }).delta ?? ''));
}
}
// React to another participant's stream chunks.
async onExternalEvent(source: Participant, event: SemanticEvent<unknown>): Promise<void> {
if (event.type === 'response.output_text.delta') {
const { delta } = event.data as { delta: string };
process.stdout.write(delta);
}
}
}Requesting streaming: true for a model whose specification has supportsStreaming: false fails request validation before the API is called.
When streaming is off, inference yields ContextItems only (ReasoningItem, FunctionCallItem, ModelMessageItem) — no semantic events on the bus. See Core concepts for how the three event kinds relate, Capabilities & Tools for the runInference signature, and OpenResponses for how completed items map to the provider spec.