Hi, i tried to create a simple koog strategy for s...
# koog-agentic-framework
p
Hi, i tried to create a simple koog strategy for streaming with tool calls:
Copy code
fun streamingWithToolsStrategy() = strategy("streaming_loop") {
    val executeMultipleTools by nodeExecuteMultipleTools(parallelTools = true)
    val nodeStreaming by nodeLLMRequestStreamingAndSendResults()

    val mapStringToRequests by node<String, List<Message.Request>> { input ->
        listOf(Message.User(content = input, metaInfo = RequestMetaInfo.Empty))
    }

    val applyRequestToSession by node<List<Message.Request>, List<Message.Request>> { input ->
        llm.writeSession {
            appendPrompt {
                input.forEach { message ->
                    when (message) {
                        is Message.User -> user(message.content)
                        is Message.Tool.Result -> tool { result(message) }
                        else -> {}
                    }
                }
            }
        }
        input
    }

    val mapToolCallsToRequests by node<List<ReceivedToolResult>, List<Message.Request>> { input ->
        input.map { it.toMessage() }
    }

    edge(nodeStart forwardTo mapStringToRequests)
    edge(mapStringToRequests forwardTo applyRequestToSession)
    edge(applyRequestToSession forwardTo nodeStreaming)
    edge(nodeStreaming forwardTo executeMultipleTools onMultipleToolCalls { true })
    edge(executeMultipleTools forwardTo mapToolCallsToRequests)
    edge(mapToolCallsToRequests forwardTo applyRequestToSession)
    edge(nodeStreaming forwardTo nodeFinish onCondition { it.filterIsInstance<Message.Tool.Call>().isEmpty() })
}
and then grab the streamed content/text via handleEvents.onLLMStreamingFrameReceived - while this does work, is this the right approach / correct so far?
s
Hi! Sorry for the late reply. Yes, the approach with onLLMStreamingFrameReceived is the correct one for now. The full example for the Koog release 0.6.4 is there - StreamingAgentWithTools.kt Could you please share what you find inconvenient in the current approach? Or perhaps something is missing in the documentation?