MockLLMBuilder

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()

Types

Link copied to clipboard

Receiver class for configuring tool behavior during testing.

Link copied to clipboard
class ToolCallReceiver<Args : Tool.Args>(tool: Tool<Args, *>, args: Args, builder: MockLLMBuilder)

Receiver class for configuring tool call responses from the LLM.

Functions

Link copied to clipboard
fun <Args : Tool.Args> addLLMAnswerExactPattern(llmAnswer: String, tool: Tool<Args, *>, args: Args)

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

Link copied to clipboard
fun <Args : Tool.Args, 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 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
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.