in agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/feature/ContextualPromptExecutor.kt [75:135]
override fun executeStreaming(
prompt: Prompt,
model: LLModel,
tools: List<ToolDescriptor>
): Flow<StreamFrame> {
@OptIn(ExperimentalUuidApi::class)
val eventId: String = Uuid.random().toString()
logger.debug { "Executing LLM streaming call (event id: $eventId, prompt: $prompt, tools: [${tools.joinToString { it.name }}])" }
return executor.executeStreaming(prompt, model, tools)
.onStart {
logger.debug { "Starting LLM streaming call (event id: $eventId)" }
context.pipeline.onLLMStreamingStarting(
eventId,
context.executionInfo,
context.runId,
prompt,
model,
tools,
context
)
}
.onEach { frame ->
logger.debug { "Received frame from LLM streaming call (event id: $eventId): $frame" }
context.pipeline.onLLMStreamingFrameReceived(
eventId,
context.executionInfo,
context.runId,
prompt,
model,
frame,
context
)
}
.catch { error ->
logger.debug(error) { "Error in LLM streaming call (event id: $eventId): $error" }
context.pipeline.onLLMStreamingFailed(
eventId,
context.executionInfo,
context.runId,
prompt,
model,
error,
context
)
throw error
}
.onCompletion { error ->
logger.debug(error) { "Finished LLM streaming call (event id: $eventId): $error" }
context.pipeline.onLLMStreamingCompleted(
eventId,
context.executionInfo,
context.runId,
prompt,
model,
tools,
context
)
}
}