John O'Reilly
11/28/2025, 3:51 PMfunctionalStrategy where it's not just doing single run i.e. user can post follow up prompts etc?John O'Reilly
11/28/2025, 4:00 PMupdate fstrategy to implement same as what's done in strategyJohn O'Reilly
11/28/2025, 4:11 PMval fstrategy = functionalStrategy<String, String> { initialInput ->
var inputMessage = initialInput
var lastAssistantMessage = ""
repeat(50) { // align with agentConfig.maxAgentIterations
println("Calling LLM with Input = $inputMessage")
var responses = requestLLMMultiple(inputMessage)
// Resolve tools until none left, mirroring graph strategy
while (responses.containsToolCalls()) {
val pendingCalls = extractToolCalls(responses)
println("Pending Calls")
println(pendingCalls.map { "${it.tool} ${it.content}" })
val results = executeMultipleTools(pendingCalls, parallelTools = true)
// Finish condition: if ExitTool is called, return its result directly
if (results.size == 1 && results.first().tool == ExitTool.name) {
return@functionalStrategy results.first().result!!.toString()
}
// Send tool results back to LLM
responses = sendMultipleToolResults(results)
}
// No more tool calls: deliver assistant message to UI and get possible user follow-up
lastAssistantMessage = responses.first().asAssistantMessage().content
val userReply = onAssistantMessage(lastAssistantMessage)
// If user provides no reply, consider conversation finished and return assistant response
if (userReply.isBlank()) {
return@functionalStrategy lastAssistantMessage
}
// Prepare for next loop iteration with user's reply
inputMessage = userReply
}
// Max iterations reached; return last assistant message
lastAssistantMessage
}Didier Villevalois
11/28/2025, 4:17 PMJohn O'Reilly
11/28/2025, 4:18 PMJohn O'Reilly
11/28/2025, 4:19 PMAIAgentJohn O'Reilly
11/28/2025, 4:19 PMfunctionalStrategy insteadDidier Villevalois
11/28/2025, 4:21 PMrepeat in your strategy, you should have access to the maxAgentIterations value through the agent config, which I believe you have access to from the AgentFunctionalContext.Vadim Briliantov
11/28/2025, 7:48 PMVadim Briliantov
11/28/2025, 7:50 PM