prompt-executor-model
Core interfaces and models for executing prompts against language models.
Overview
This module defines the fundamental interfaces and models for executing prompts against language models. It provides the PromptExecutor interface which serves as the foundation for all prompt execution implementations, supporting both synchronous and streaming execution modes, with or without tool assistance.
Additionally, this module provides implementations of the PromptExecutor interface for executing prompts with Large Language Models (LLMs). It includes:
SingleLLMPromptExecutor: Executes prompts using a single LLM clientMultiLLMPromptExecutor: Executes prompts across multiple LLM providers with fallback capabilitiesRoutingLLMPromptExecutor: Routes requests across multiple clients per provider
Using in your project
Add the dependency to your project:
dependencies {
implementation("ai.koog.prompt:prompt-executor-model:$version")
}When implementing a custom prompt executor or working with existing implementations, you'll need to use the interfaces defined in this module:
// Using the PromptExecutor interface
val executor: PromptExecutor = getPromptExecutorImplementation() // obtain an implementation
val result = executor.execute(prompt, model)Example of usage
// Creating a prompt executor implementation
class MyPromptExecutor : PromptExecutor() {
override suspend fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response> {
// Implementation details
}
override suspend fun executeStreaming(prompt: Prompt, model: LLModel): Flow<String> {
// Implementation details
}
}
// Using a prompt executor
suspend fun processPrompt(executor: PromptExecutor, prompt: Prompt, model: LLModel) {
val response = executor.execute(prompt, model)
println("Response: $response")
// With streaming
executor.executeStreaming(prompt, model).collect { chunk ->
print(chunk)
}
}These executors handle both standard and streaming execution of prompts, delegating the actual LLM interaction to the provided LLM clients.
Custom executors and model resolution
Use DynamicPromptExecutor as the base class for new custom executors that need fallback, routing, model substitution, or any other model-resolution policy. Implement resolveModel(...) and the ResolvedModel-based execution methods. The LLModel-based methods are finalized there so each request passes through model resolution once before execution.
Use PromptExecutor directly only when the executor does not need a model-resolution hook.
MultiLLMPromptExecutor and RoutingLLMPromptExecutor remain open for source and binary compatibility with existing subclasses, but they are not the preferred base classes for new custom executor implementations. If you subclass either class, override the ResolvedModel-based methods by default so the built-in fallback and routing resolution still runs. Override the LLModel-based methods only when you intentionally take over the full model-resolution and execution flow; if those overrides do not call super, resolveModel(...) is bypassed.
import ai.koog.prompt.dsl.prompt
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
import ai.koog.prompt.executor.clients.openai.OpenAILLMClient
import ai.koog.prompt.executor.clients.openai.OpenAIModels
import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor
import ai.koog.prompt.executor.llms.SingleLLMPromptExecutor
import ai.koog.prompt.llm.LLMProvider
// Example with SingleLLMPromptExecutor
val openAIClient = OpenAILLMClient(apiKey = "your-api-key")
val singleExecutor = SingleLLMPromptExecutor(openAIClient)
// Example with MultiLLMPromptExecutor
val anthropicClient = AnthropicLLMClient(apiKey = "your-anthropic-key")
val multiExecutor = MultiLLMPromptExecutor(
LLMProvider.OpenAI to openAIClient,
LLMProvider.Anthropic to anthropicClient
)
// Execute a prompt
val prompt = prompt("example") {
system("You are a helpful assistant.")
user("Tell me about Kotlin.")
}
val model = OpenAIModels.Chat.GPT4o
val responses = multiExecutor.execute(prompt, model)Core interfaces and models for executing prompts against language models.
Overview
This module defines the fundamental interfaces and models for executing prompts against language models. It provides the PromptExecutor interface which serves as the foundation for all prompt execution implementations, supporting both synchronous and streaming execution modes, with or without tool assistance.
Additionally, this module provides implementations of the PromptExecutor interface for executing prompts with Large Language Models (LLMs). It includes:
SingleLLMPromptExecutor: Executes prompts using a single LLM clientMultiLLMPromptExecutor: Executes prompts across multiple LLM providers with fallback capabilitiesRoutingLLMPromptExecutor: Routes requests across multiple clients per provider
Using in your project
Add the dependency to your project:
dependencies {
implementation("ai.koog.prompt:prompt-executor-model:$version")
}When implementing a custom prompt executor or working with existing implementations, you'll need to use the interfaces defined in this module:
// Using the PromptExecutor interface
val executor: PromptExecutor = getPromptExecutorImplementation() // obtain an implementation
val result = executor.execute(prompt, model)Example of usage
// Creating a prompt executor implementation
class MyPromptExecutor : PromptExecutor() {
override suspend fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response> {
// Implementation details
}
override suspend fun executeStreaming(prompt: Prompt, model: LLModel): Flow<String> {
// Implementation details
}
}
// Using a prompt executor
suspend fun processPrompt(executor: PromptExecutor, prompt: Prompt, model: LLModel) {
val response = executor.execute(prompt, model)
println("Response: $response")
// With streaming
executor.executeStreaming(prompt, model).collect { chunk ->
print(chunk)
}
}These executors handle both standard and streaming execution of prompts, delegating the actual LLM interaction to the provided LLM clients.
Custom executors and model resolution
Use DynamicPromptExecutor as the base class for new custom executors that need fallback, routing, model substitution, or any other model-resolution policy. Implement resolveModel(...) and the ResolvedModel-based execution methods. The LLModel-based methods are finalized there so each request passes through model resolution once before execution.
Use PromptExecutor directly only when the executor does not need a model-resolution hook.
MultiLLMPromptExecutor and RoutingLLMPromptExecutor remain open for source and binary compatibility with existing subclasses, but they are not the preferred base classes for new custom executor implementations. If you subclass either class, override the ResolvedModel-based methods by default so the built-in fallback and routing resolution still runs. Override the LLModel-based methods only when you intentionally take over the full model-resolution and execution flow; if those overrides do not call super, resolveModel(...) is bypassed.
import ai.koog.prompt.dsl.prompt
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
import ai.koog.prompt.executor.clients.openai.OpenAILLMClient
import ai.koog.prompt.executor.clients.openai.OpenAIModels
import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor
import ai.koog.prompt.executor.llms.SingleLLMPromptExecutor
import ai.koog.prompt.llm.LLMProvider
// Example with SingleLLMPromptExecutor
val openAIClient = OpenAILLMClient(apiKey = "your-api-key")
val singleExecutor = SingleLLMPromptExecutor(openAIClient)
// Example with MultiLLMPromptExecutor
val anthropicClient = AnthropicLLMClient(apiKey = "your-anthropic-key")
val multiExecutor = MultiLLMPromptExecutor(
LLMProvider.OpenAI to openAIClient,
LLMProvider.Anthropic to anthropicClient
)
// Execute a prompt
val prompt = prompt("example") {
system("You are a helpful assistant.")
user("Tell me about Kotlin.")
}
val model = OpenAIModels.Chat.GPT4o
val responses = multiExecutor.execute(prompt, model)Core interfaces and models for executing prompts against language models.
Overview
This module defines the fundamental interfaces and models for executing prompts against language models. It provides the PromptExecutor interface which serves as the foundation for all prompt execution implementations, supporting both synchronous and streaming execution modes, with or without tool assistance.
Additionally, this module provides implementations of the PromptExecutor interface for executing prompts with Large Language Models (LLMs). It includes:
SingleLLMPromptExecutor: Executes prompts using a single LLM clientMultiLLMPromptExecutor: Executes prompts across multiple LLM providers with fallback capabilitiesRoutingLLMPromptExecutor: Routes requests across multiple clients per provider
Using in your project
Add the dependency to your project:
dependencies {
implementation("ai.koog.prompt:prompt-executor-model:$version")
}When implementing a custom prompt executor or working with existing implementations, you'll need to use the interfaces defined in this module:
// Using the PromptExecutor interface
val executor: PromptExecutor = getPromptExecutorImplementation() // obtain an implementation
val result = executor.execute(prompt, model)Example of usage
// Creating a prompt executor implementation
class MyPromptExecutor : PromptExecutor() {
override suspend fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response> {
// Implementation details
}
override suspend fun executeStreaming(prompt: Prompt, model: LLModel): Flow<String> {
// Implementation details
}
}
// Using a prompt executor
suspend fun processPrompt(executor: PromptExecutor, prompt: Prompt, model: LLModel) {
val response = executor.execute(prompt, model)
println("Response: $response")
// With streaming
executor.executeStreaming(prompt, model).collect { chunk ->
print(chunk)
}
}These executors handle both standard and streaming execution of prompts, delegating the actual LLM interaction to the provided LLM clients.
Custom executors and model resolution
Use DynamicPromptExecutor as the base class for new custom executors that need fallback, routing, model substitution, or any other model-resolution policy. Implement resolveModel(...) and the ResolvedModel-based execution methods. The LLModel-based methods are finalized there so each request passes through model resolution once before execution.
Use PromptExecutor directly only when the executor does not need a model-resolution hook.
MultiLLMPromptExecutor and RoutingLLMPromptExecutor remain open for source and binary compatibility with existing subclasses, but they are not the preferred base classes for new custom executor implementations. If you subclass either class, override the ResolvedModel-based methods by default so the built-in fallback and routing resolution still runs. Override the LLModel-based methods only when you intentionally take over the full model-resolution and execution flow; if those overrides do not call super, resolveModel(...) is bypassed.
import ai.koog.prompt.dsl.prompt
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
import ai.koog.prompt.executor.clients.openai.OpenAILLMClient
import ai.koog.prompt.executor.clients.openai.OpenAIModels
import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor
import ai.koog.prompt.executor.llms.SingleLLMPromptExecutor
import ai.koog.prompt.llm.LLMProvider
// Example with SingleLLMPromptExecutor
val openAIClient = OpenAILLMClient(apiKey = "your-api-key")
val singleExecutor = SingleLLMPromptExecutor(openAIClient)
// Example with MultiLLMPromptExecutor
val anthropicClient = AnthropicLLMClient(apiKey = "your-anthropic-key")
val multiExecutor = MultiLLMPromptExecutor(
LLMProvider.OpenAI to openAIClient,
LLMProvider.Anthropic to anthropicClient
)
// Execute a prompt
val prompt = prompt("example") {
system("You are a helpful assistant.")
user("Tell me about Kotlin.")
}
val model = OpenAIModels.Chat.GPT4o
val responses = multiExecutor.execute(prompt, model)Core interfaces and models for executing prompts against language models.
Overview
This module defines the fundamental interfaces and models for executing prompts against language models. It provides the PromptExecutor interface which serves as the foundation for all prompt execution implementations, supporting both synchronous and streaming execution modes, with or without tool assistance.
Additionally, this module provides implementations of the PromptExecutor interface for executing prompts with Large Language Models (LLMs). It includes:
SingleLLMPromptExecutor: Executes prompts using a single LLM clientMultiLLMPromptExecutor: Executes prompts across multiple LLM providers with fallback capabilitiesRoutingLLMPromptExecutor: Routes requests across multiple clients per provider
Using in your project
Add the dependency to your project:
dependencies {
implementation("ai.koog.prompt:prompt-executor-model:$version")
}When implementing a custom prompt executor or working with existing implementations, you'll need to use the interfaces defined in this module:
// Using the PromptExecutor interface
val executor: PromptExecutor = getPromptExecutorImplementation() // obtain an implementation
val result = executor.execute(prompt, model)Example of usage
// Creating a prompt executor implementation
class MyPromptExecutor : PromptExecutor() {
override suspend fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response> {
// Implementation details
}
override suspend fun executeStreaming(prompt: Prompt, model: LLModel): Flow<String> {
// Implementation details
}
}
// Using a prompt executor
suspend fun processPrompt(executor: PromptExecutor, prompt: Prompt, model: LLModel) {
val response = executor.execute(prompt, model)
println("Response: $response")
// With streaming
executor.executeStreaming(prompt, model).collect { chunk ->
print(chunk)
}
}These executors handle both standard and streaming execution of prompts, delegating the actual LLM interaction to the provided LLM clients.
Custom executors and model resolution
Use DynamicPromptExecutor as the base class for new custom executors that need fallback, routing, model substitution, or any other model-resolution policy. Implement resolveModel(...) and the ResolvedModel-based execution methods. The LLModel-based methods are finalized there so each request passes through model resolution once before execution.
Use PromptExecutor directly only when the executor does not need a model-resolution hook.
MultiLLMPromptExecutor and RoutingLLMPromptExecutor remain open for source and binary compatibility with existing subclasses, but they are not the preferred base classes for new custom executor implementations. If you subclass either class, override the ResolvedModel-based methods by default so the built-in fallback and routing resolution still runs. Override the LLModel-based methods only when you intentionally take over the full model-resolution and execution flow; if those overrides do not call super, resolveModel(...) is bypassed.
import ai.koog.prompt.dsl.prompt
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
import ai.koog.prompt.executor.clients.openai.OpenAILLMClient
import ai.koog.prompt.executor.clients.openai.OpenAIModels
import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor
import ai.koog.prompt.executor.llms.SingleLLMPromptExecutor
import ai.koog.prompt.llm.LLMProvider
// Example with SingleLLMPromptExecutor
val openAIClient = OpenAILLMClient(apiKey = "your-api-key")
val singleExecutor = SingleLLMPromptExecutor(openAIClient)
// Example with MultiLLMPromptExecutor
val anthropicClient = AnthropicLLMClient(apiKey = "your-anthropic-key")
val multiExecutor = MultiLLMPromptExecutor(
LLMProvider.OpenAI to openAIClient,
LLMProvider.Anthropic to anthropicClient
)
// Execute a prompt
val prompt = prompt("example") {
system("You are a helpful assistant.")
user("Tell me about Kotlin.")
}
val model = OpenAIModels.Chat.GPT4o
val responses = multiExecutor.execute(prompt, model)Core interfaces and models for executing prompts against language models.
Overview
This module defines the fundamental interfaces and models for executing prompts against language models. It provides the PromptExecutor interface which serves as the foundation for all prompt execution implementations, supporting both synchronous and streaming execution modes, with or without tool assistance.
Additionally, this module provides implementations of the PromptExecutor interface for executing prompts with Large Language Models (LLMs). It includes:
SingleLLMPromptExecutor: Executes prompts using a single LLM clientMultiLLMPromptExecutor: Executes prompts across multiple LLM providers with fallback capabilitiesRoutingLLMPromptExecutor: Routes requests across multiple clients per provider
Using in your project
Add the dependency to your project:
dependencies {
implementation("ai.koog.prompt:prompt-executor-model:$version")
}When implementing a custom prompt executor or working with existing implementations, you'll need to use the interfaces defined in this module:
// Using the PromptExecutor interface
val executor: PromptExecutor = getPromptExecutorImplementation() // obtain an implementation
val result = executor.execute(prompt, model)Example of usage
// Creating a prompt executor implementation
class MyPromptExecutor : PromptExecutor() {
override suspend fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response> {
// Implementation details
}
override suspend fun executeStreaming(prompt: Prompt, model: LLModel): Flow<String> {
// Implementation details
}
}
// Using a prompt executor
suspend fun processPrompt(executor: PromptExecutor, prompt: Prompt, model: LLModel) {
val response = executor.execute(prompt, model)
println("Response: $response")
// With streaming
executor.executeStreaming(prompt, model).collect { chunk ->
print(chunk)
}
}These executors handle both standard and streaming execution of prompts, delegating the actual LLM interaction to the provided LLM clients.
Custom executors and model resolution
Use DynamicPromptExecutor as the base class for new custom executors that need fallback, routing, model substitution, or any other model-resolution policy. Implement resolveModel(...) and the ResolvedModel-based execution methods. The LLModel-based methods are finalized there so each request passes through model resolution once before execution.
Use PromptExecutor directly only when the executor does not need a model-resolution hook.
MultiLLMPromptExecutor and RoutingLLMPromptExecutor remain open for source and binary compatibility with existing subclasses, but they are not the preferred base classes for new custom executor implementations. If you subclass either class, override the ResolvedModel-based methods by default so the built-in fallback and routing resolution still runs. Override the LLModel-based methods only when you intentionally take over the full model-resolution and execution flow; if those overrides do not call super, resolveModel(...) is bypassed.
import ai.koog.prompt.dsl.prompt
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
import ai.koog.prompt.executor.clients.openai.OpenAILLMClient
import ai.koog.prompt.executor.clients.openai.OpenAIModels
import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor
import ai.koog.prompt.executor.llms.SingleLLMPromptExecutor
import ai.koog.prompt.llm.LLMProvider
// Example with SingleLLMPromptExecutor
val openAIClient = OpenAILLMClient(apiKey = "your-api-key")
val singleExecutor = SingleLLMPromptExecutor(openAIClient)
// Example with MultiLLMPromptExecutor
val anthropicClient = AnthropicLLMClient(apiKey = "your-anthropic-key")
val multiExecutor = MultiLLMPromptExecutor(
LLMProvider.OpenAI to openAIClient,
LLMProvider.Anthropic to anthropicClient
)
// Execute a prompt
val prompt = prompt("example") {
system("You are a helpful assistant.")
user("Tell me about Kotlin.")
}
val model = OpenAIModels.Chat.GPT4o
val responses = multiExecutor.execute(prompt, model)Core interfaces and models for executing prompts against language models.
Overview
This module defines the fundamental interfaces and models for executing prompts against language models. It provides the PromptExecutor interface which serves as the foundation for all prompt execution implementations, supporting both synchronous and streaming execution modes, with or without tool assistance.
Additionally, this module provides implementations of the PromptExecutor interface for executing prompts with Large Language Models (LLMs). It includes:
SingleLLMPromptExecutor: Executes prompts using a single LLM clientMultiLLMPromptExecutor: Executes prompts across multiple LLM providers with fallback capabilitiesRoutingLLMPromptExecutor: Routes requests across multiple clients per provider
Using in your project
Add the dependency to your project:
dependencies {
implementation("ai.koog.prompt:prompt-executor-model:$version")
}When implementing a custom prompt executor or working with existing implementations, you'll need to use the interfaces defined in this module:
// Using the PromptExecutor interface
val executor: PromptExecutor = getPromptExecutorImplementation() // obtain an implementation
val result = executor.execute(prompt, model)Example of usage
// Creating a prompt executor implementation
class MyPromptExecutor : PromptExecutor() {
override suspend fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): List<Message.Response> {
// Implementation details
}
override suspend fun executeStreaming(prompt: Prompt, model: LLModel): Flow<String> {
// Implementation details
}
}
// Using a prompt executor
suspend fun processPrompt(executor: PromptExecutor, prompt: Prompt, model: LLModel) {
val response = executor.execute(prompt, model)
println("Response: $response")
// With streaming
executor.executeStreaming(prompt, model).collect { chunk ->
print(chunk)
}
}These executors handle both standard and streaming execution of prompts, delegating the actual LLM interaction to the provided LLM clients.
Custom executors and model resolution
Use DynamicPromptExecutor as the base class for new custom executors that need fallback, routing, model substitution, or any other model-resolution policy. Implement resolveModel(...) and the ResolvedModel-based execution methods. The LLModel-based methods are finalized there so each request passes through model resolution once before execution.
Use PromptExecutor directly only when the executor does not need a model-resolution hook.
MultiLLMPromptExecutor and RoutingLLMPromptExecutor remain open for source and binary compatibility with existing subclasses, but they are not the preferred base classes for new custom executor implementations. If you subclass either class, override the ResolvedModel-based methods by default so the built-in fallback and routing resolution still runs. Override the LLModel-based methods only when you intentionally take over the full model-resolution and execution flow; if those overrides do not call super, resolveModel(...) is bypassed.
import ai.koog.prompt.dsl.prompt
import ai.koog.prompt.executor.clients.anthropic.AnthropicLLMClient
import ai.koog.prompt.executor.clients.openai.OpenAILLMClient
import ai.koog.prompt.executor.clients.openai.OpenAIModels
import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor
import ai.koog.prompt.executor.llms.SingleLLMPromptExecutor
import ai.koog.prompt.llm.LLMProvider
// Example with SingleLLMPromptExecutor
val openAIClient = OpenAILLMClient(apiKey = "your-api-key")
val singleExecutor = SingleLLMPromptExecutor(openAIClient)
// Example with MultiLLMPromptExecutor
val anthropicClient = AnthropicLLMClient(apiKey = "your-anthropic-key")
val multiExecutor = MultiLLMPromptExecutor(
LLMProvider.OpenAI to openAIClient,
LLMProvider.Anthropic to anthropicClient
)
// Execute a prompt
val prompt = prompt("example") {
system("You are a helpful assistant.")
user("Tell me about Kotlin.")
}
val model = OpenAIModels.Chat.GPT4o
val responses = multiExecutor.execute(prompt, model)