onLLMStreamingFrameReceived
abstract fun onLLMStreamingFrameReceived(handler: suspend (eventContext: LLMStreamingFrameReceivedContext) -> Unit)(source)
Registers a handler to be invoked when stream frames are received during streaming.
This handler is called for each stream frame as it arrives from the language model, enabling real-time processing, monitoring, or aggregation of streaming content.
Parameters
handler
The handler function that receives a LLMStreamingFrameReceivedContext containing the run ID and the stream frame with partial response data.
Example:
onLLMStreamingFrameReceived { eventContext ->
when (val frame = eventContext.streamFrame) {
is StreamFrame.TextDelta -> processText(frame.text)
is StreamFrame.ReasoningDelta -> processReasoning(frame.text, frame.summary)
is StreamFrame.ToolCallComplete -> processTool(frame)
else -> {} // Handle other frame types
}
}Content copied to clipboard