DynamicPromptExecutor

A PromptExecutor that introduces an explicit resolveModel step before every LLM operation.

Prefer this base class for new custom prompt executors that need fallback, routing, model substitution, or any other model-resolution policy.

Subclasses use resolveModel to translate a caller-requested LLModel into a ResolvedModel — for example, to swap in a fallback model when the requested one is not directly available. Each PromptExecutor entry point taking a plain LLModel is finalized here and delegates to the matching ResolvedModel-based overload, so model resolution always happens exactly once per call and subclasses cannot bypass it.

Subclasses must implement resolveModel together with the ResolvedModel-based execute, executeStreaming, executeMultipleChoices, and moderate overloads.

Inside those overrides, do not delegate to the LLModel-based overloads. They are finalized to re-enter model resolution and will recurse.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract suspend override fun execute(prompt: Prompt, resolvedModel: ResolvedModel, tools: List<ToolDescriptor> = emptyList()): Message.Assistant

Executes prompt against an already-resolved resolvedModel.

suspend override fun execute(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor> = emptyList()): Message.Assistant

Finalized to enforce that every call resolves through resolveModel before dispatch. Subclasses customize behavior by overriding the ResolvedModel-based execute overload.

Link copied to clipboard
abstract suspend override fun executeMultipleChoices(prompt: Prompt, resolvedModel: ResolvedModel, tools: List<ToolDescriptor>): LLMChoice

Returns multiple independent choices from an already-resolved resolvedModel.

suspend override fun executeMultipleChoices(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor>): LLMChoice

Finalized to enforce that every call resolves through resolveModel before dispatch. Subclasses customize behavior by overriding the ResolvedModel-based executeMultipleChoices overload.

Link copied to clipboard
abstract override fun executeStreaming(prompt: Prompt, resolvedModel: ResolvedModel, tools: List<ToolDescriptor> = emptyList()): Flow<StreamFrame>

Streams the response for prompt against an already-resolved resolvedModel.

override fun executeStreaming(prompt: Prompt, model: LLModel, tools: List<ToolDescriptor> = emptyList()): Flow<StreamFrame>

Finalized to enforce that every call resolves through resolveModel before dispatch. Subclasses customize behavior by overriding the ResolvedModel-based executeStreaming overload.

Link copied to clipboard
suspend fun <T> PromptExecutor.executeStructured(prompt: Prompt, model: LLModel, config: StructuredRequestConfig<T>, fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>
inline suspend fun <T> PromptExecutor.executeStructured(prompt: Prompt, model: LLModel, examples: List<T> = emptyList(), fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>
suspend fun <T> PromptExecutor.executeStructured(prompt: Prompt, model: LLModel, serializer: KSerializer<T>, examples: List<T> = emptyList(), fixingParser: StructureFixingParser? = null): Result<StructuredResponse<T>>

Executes a prompt with structured output, enhancing it with schema instructions or native structured output parameter, and parses the response into the defined structure.

Link copied to clipboard

Basic JSON schema generator required for the given model. Return BasicJsonSchemaGenerator by default.

Link copied to clipboard

Standard JSON schema generator required for the given model. Return StandardJsonSchemaGenerator by default.

Link copied to clipboard
open suspend fun models(): List<LLModel>

Retrieves a list of available models from all LLM clients managed by this executor.

Link copied to clipboard
abstract suspend override fun moderate(prompt: Prompt, model: ResolvedModel): ModerationResult

Moderates prompt against an already-resolved model.

suspend override fun moderate(prompt: Prompt, model: LLModel): ModerationResult

Finalized to enforce that every call resolves through resolveModel before dispatch. Subclasses customize behavior by overriding the ResolvedModel-based moderate overload.

Link copied to clipboard

Parses a structured response from the assistant message using the provided structured output configuration and language model. If a fixing parser is specified in the configuration, it will be used; otherwise, the structure will be parsed directly.

Link copied to clipboard
abstract suspend override fun resolveModel(model: LLModel, promptExecutorOperation: PromptExecutorOperation): ResolvedModel

Resolves model into the ResolvedModel to actually use for the given promptExecutorOperation.