MockLLMBuilder

class MockLLMBuilder(clock: Clock, tokenizer: Tokenizer? = null)(source)

Builder class for creating mock LLM executors for testing.

This class provides a fluent API for configuring mock responses for LLM requests and tool calls. It allows you to define how the LLM should respond to different inputs and how tools should behave when called during 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."
}
}

Constructors

Link copied to clipboard
constructor(clock: Clock, tokenizer: Tokenizer? = null)

Types

Link copied to clipboard
class MixedResultsReceiver<Args : ToolArgs>(toolCalls: List<Pair<Tool<Args, *>, Args>>, responses: List<String>, builder: MockLLMBuilder)

Represents a class responsible for handling and managing mixed tool call results based on mock responses and predefined configurations.

Link copied to clipboard

Receiver class for configuring tool behavior during testing.

Link copied to clipboard
class MultiToolCallReceiver<Args : ToolArgs>(toolCalls: List<Pair<Tool<Args, *>, Args>>, builder: MockLLMBuilder)

Receiver class for configuring tool call responses from the LLM. This class is part of the fluent API for configuring how the LLM should respond with tool calls when it receives specific inputs.

Link copied to clipboard
class ToolCallReceiver<Args : ToolArgs>(tool: Tool<Args, *>, args: Args, toolCallId: String?, builder: MockLLMBuilder)

Receiver class for configuring tool call responses from the LLM.

Properties

Link copied to clipboard

Determines whether the last message handled in a sequence should focus specifically on the most recent message categorized as Message.Assistant when resolving mock responses.

Functions

Link copied to clipboard
fun <Args : ToolArgs> addLLMAnswerExactPattern(pattern: String, toolCalls: List<Pair<Tool<Args, *>, Args>>)

Adds an exact pattern match for an LLM answer that triggers a set of tool calls.

fun <Args : ToolArgs> addLLMAnswerExactPattern(pattern: String, toolCalls: List<Pair<Tool<Args, *>, Args>>, responses: List<String>)

Adds an exact pattern match for an LLM answer that triggers a set of tool calls with predefined responses.

fun <Args : ToolArgs> addLLMAnswerExactPattern(pattern: String, tool: Tool<Args, *>, args: Args, toolCallId: String?)

Adds an exact pattern match for an LLM answer that triggers a tool call.

Link copied to clipboard
fun <Args : ToolArgs> addLLMAnswerPartialPattern(pattern: String, toolCalls: List<Pair<Tool<Args, *>, Args>>)

Adds a partial pattern match for an LLM answer that triggers a set of tool calls.

fun <Args : ToolArgs> addLLMAnswerPartialPattern(pattern: String, tool: Tool<Args, *>, args: Args)

Adds a partial pattern match for an LLM answer that triggers a tool call.

fun <Args : ToolArgs> addLLMAnswerPartialPattern(pattern: String, toolCalls: List<Pair<Tool<Args, *>, Args>>, responses: List<String>)

Adds a partial pattern match for an LLM answer that triggers a set of tool calls with predefined responses.

Link copied to clipboard

Adds a specific moderation response for an exact pattern match.

Link copied to clipboard

Associates a given moderation response with a specific partial pattern.

Link copied to clipboard
fun <Args : ToolArgs, Result : ToolResult> addToolAction(tool: Tool<Args, Result>, argsCondition: suspend (Args) -> Boolean = { true }, action: suspend (Args) -> Result)

Adds a tool action to be executed when a tool call matches the specified condition.

Link copied to clipboard

Convenience extension function for configuring a text tool to always return the specified string.

Link copied to clipboard

Convenience extension function for configuring a text tool to always execute the specified action and return its string result.

Link copied to clipboard

Builds and returns a PromptExecutor configured with the mock responses and tool actions.

Link copied to clipboard

Convenience extension function for configuring a text tool to execute the specified action and return its string result when it receives matching arguments.

Link copied to clipboard

Creates a mock response with a combination of tool calls and predefined string responses.

Link copied to clipboard

Creates a mock for a list of LLM tool calls.

fun <Args : ToolArgs> mockLLMToolCall(tool: Tool<Args, *>, args: Args, toolCallId: String? = null): MockLLMBuilder.ToolCallReceiver<Args>

Creates a mock for an LLM tool call.

Link copied to clipboard

Mocks a tool call for the provided tool function and arguments.

Link copied to clipboard
Link copied to clipboard

Associates a tool function with the MockLLMBuilder to create a MockToolFromCallableReceiver instance.

Link copied to clipboard
infix fun String.onCondition(condition: (String) -> Boolean): MockLLMBuilder

Configures the LLM to respond with this string when the user request satisfies the specified condition.

Link copied to clipboard

Configures the LLM to respond with this string when the user request contains the specified pattern.

Link copied to clipboard

Configures the LLM to respond with this string when the user request exactly matches the specified pattern.

Link copied to clipboard

Sets the default moderation response to the provided result.

Link copied to clipboard
fun setDefaultResponse(response: String)

Sets the default response to be returned when no other response matches.

Link copied to clipboard

Sets the tool registry to be used for tool execution.