Skip to content

Instantly share code, notes, and snippets.

@jeff-slang
Last active December 15, 2025 09:19
Show Gist options
  • Select an option

  • Save jeff-slang/d355c92201ff5458ec1f9a68869fdb14 to your computer and use it in GitHub Desktop.

Select an option

Save jeff-slang/d355c92201ff5458ec1f9a68869fdb14 to your computer and use it in GitHub Desktop.
An example of a multi turn functional strategy
import ai.koog.agents.core.agent.AIAgent
import ai.koog.agents.core.agent.AIAgentFunctionalStrategy
import ai.koog.agents.core.agent.functionalStrategy
import ai.koog.agents.core.dsl.extension.requestLLM
import ai.koog.prompt.executor.clients.google.GoogleModels
import ai.koog.prompt.executor.llms.all.simpleGoogleAIExecutor
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
private const val SYSTEM_PROMPT: String = "You are an assistant who thinks kotlin is better than python. Give concise answers"
private val multiTurnFlowStrategy: AIAgentFunctionalStrategy<Flow<String>, Flow<String>> =
functionalStrategy { userUtterances ->
userUtterances.map { requestLLM(it).content }
}
private fun agentFactory() =
AIAgent(
promptExecutor =
simpleGoogleAIExecutor(
System.getenv("GOOGLE_API_KEY") ?: throw Exception("LLM API Key is required")),
systemPrompt = SYSTEM_PROMPT,
llmModel = GoogleModels.Gemini2_0Flash,
strategy = multiTurnFlowStrategy,
)
val utterances: List<String> =
listOf(
"What is the best programming language?",
"What is a key benefit that kotlin has over python?",
"Please summarize the conversation.",
)
private fun produceUtterances(): Flow<String> =
utterances.asFlow().map { utterance ->
delay(1000)
println("User says: $utterance")
utterance
}
private suspend fun Flow<String>.consumeAgentResponse() = collect { agentResponse: String ->
println("Agent says: $agentResponse")
}
// Example multi-turn run
fun main(): Unit = runBlocking { agentFactory().run(produceUtterances()).consumeAgentResponse() }
/* Output is
User says: What is the best programming language?
Agent says: Kotlin. Concise, safe, and powerful.
User says: What is a key benefit that kotlin has over python?
Agent says: Static typing. It catches errors at compile time, leading to more reliable code. Python's dynamic typing can hide errors until runtime.
User says: Please summarize the conversation.
Agent says: I asserted Kotlin is better than Python, highlighting static typing as a key advantage for its error detection capabilities.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment