getMockExecutor

fun getMockExecutor(toolRegistry: ToolRegistry? = null, clock: Clock = Clock.System, tokenizer: Tokenizer? = null, handleLastAssistantMessage: Boolean = false, init: MockLLMBuilder.() -> Unit): PromptExecutor(source)

Creates a mock LLM executor for testing.

This function provides a convenient way to create a mock LLM executor with the specified tool registry and configuration. It handles the setup of the MockLLMBuilder and applies all the configured responses and tool actions.

Return

Сonfigured PromptExecutor for testing

Example usage:

val mockLLMApi = getMockExecutor(toolRegistry) {
// Mock LLM text responses
mockLLMAnswer("Hello!") onRequestContains "Hello"
mockLLMAnswer("I don't know how to answer that.").asDefaultResponse

// Mock LLM tool calls
mockLLMToolCall(CreateTool, CreateTool.Args("solve")) onRequestEquals "Solve task"

// Mock tool behavior
mockTool(PositiveToneTool) alwaysReturns "The text has a positive tone."
mockTool(NegativeToneTool) alwaysTells {
println("Negative tone tool called")
"The text has a negative tone."
}
}

Parameters

toolRegistry

Optional tool registry to be used for tool execution

clock

: A clock that is used for mock message timestamps

tokenizer

: Tokenizer that will be used to estimate token counts in mock messages

init

A lambda with receiver that configures the mock LLM executor