James Ward
09/19/2025, 12:11 PMedge(nodeCallLLM forwardTo nodeFinish onAssistantMessage { true }) to handle it and edge(nodeCallLLM forwardTo executeToolCall onToolCall { true }) doesn't. The Assistant message is a <thinking> block. Any ideas?James Ward
09/19/2025, 12:36 PMval nodeCallLLM by nodeLLMRequestMultiple()
val filterThinking by node<List<Message>, Message> { input ->
input.firstOrNull { it is Message.Tool } ?: input.first()
}
edge(nodeStart forwardTo nodeCallLLM)
edge(nodeCallLLM forwardTo filterThinking)El Anthony
09/19/2025, 5:00 PMVadim Briliantov
09/22/2025, 11:55 AMnodeLLMRequestMultiple and nodeExecuteMultipleTools . Please feel free to check out how the default singleRunStrategy strategy is implemented here: https://github.com/JetBrains/koog/blob/eaabdfa8c9605172e98a495b67505cadd6d08199/ag[…]ain/kotlin/ai/koog/agents/core/agent/AIAgentSimpleStrategies.kt
You can also implement parallel tool execution if you want as it’s done there, if your LLM outputs a mix of multiple ToolCalls + assistant messagesVadim Briliantov
09/22/2025, 11:55 AMVadim Briliantov
09/22/2025, 11:57 AMnodeExecuteMultipleTools has parallelTools = true/false flag
And there’s also onMultipleToolCalls { ... } condition that does exactly the filtering you need:
public infix fun <IncomingOutput, OutgoingInput> AIAgentEdgeBuilderIntermediate<IncomingOutput, List<Message.Response>, OutgoingInput>.onMultipleToolCalls(
block: suspend (List<Message.Tool.Call>) -> Boolean
): AIAgentEdgeBuilderIntermediate<IncomingOutput, List<Message.Tool.Call>, OutgoingInput> {
return onIsInstance(List::class)
.transformed { it to it.filterIsInstance<Message.Tool.Call>() }
// skipping this edge in case we have list of only assistant messages
.onCondition { (_, filtered) -> filtered.any() }
.transformed { (_, filtered) -> filtered }
.onCondition { toolCalls -> block(toolCalls) }El Anthony
09/22/2025, 7:20 PMprivate val thinkPart = Regex( "think.*/think[ \n]*", setOf(RegexOption.MULTILINE, RegexOption.DOT_MATCHES_ALL))
private fun parseResponse(response: OllamaChatResponseDTO): ListMessage.Response {
val messages = response.message ?: return emptyList()
val content = messages.content.replace( thinkPart, "") // removes the think part
val toolCalls = messages.toolCalls ?: emptyList()El Anthony
09/23/2025, 1:34 PMprotected suspend fun executeSingle(prompt: Prompt, tools: List<ToolDescriptor>): Message.Response =
executeMultiple(prompt, tools).first()Vadim Briliantov
09/23/2025, 2:57 PMEl Anthony
09/23/2025, 6:23 PMval strategy = strategy<String, String>("general") {
val nodeCallLLM by nodeLLMRequestMultiple()
val nodeExecuteMultipleTools by nodeExecuteMultipleTools()
val nodeSendMultipleToolResults by nodeLLMSendMultipleToolResults()
edge(nodeStart forwardTo nodeCallLLM)
// edge(nodeCallLLM forwardTo nodeExecuteTool onToolCall { true })
edge(
nodeCallLLM forwardTo nodeFinish
onMultipleAssistantMessages {
!it.all { msg -> emptyResult.matches(msg.content) }
}
transformed { messages ->
messages.filter { msg -> !emptyResult.matches(msg.content) }
.joinToString(" ") { it.content.replace( thinkContent, "") }
}
)
edge(nodeCallLLM forwardTo nodeExecuteMultipleTools onMultipleToolCalls { true })
edge(nodeExecuteMultipleTools forwardTo nodeSendMultipleToolResults)
// edge(nodeSendMultipleToolResults forwardTo nodeFinish onAssistantMessage { true })
edge(nodeSendMultipleToolResults forwardTo nodeFinish
onMultipleAssistantMessages { true }
transformed { it.joinToString(" ") { msg -> msg.content.replace( thinkContent, "") } }
)
edge(nodeSendMultipleToolResults forwardTo nodeExecuteMultipleTools onMultipleToolCalls { true })
}
With this model, although it is a single tool call, it requires nodeLLMRequestMultiple, nodeExecuteMultipleTools, and nodeLLMSendMultipleToolResults.
Thanks!