Package akka.javasdk.testkit
Class TestModelProvider
Object
akka.javasdk.testkit.TestModelProvider
- All Implemented Interfaces:
akka.javasdk.agent.ModelProvider,akka.javasdk.agent.ModelProvider.Custom
public final class TestModelProvider
extends Object
implements akka.javasdk.agent.ModelProvider.Custom
A
ModelProvider implementation for testing purposes that does not use a real AI model. It
allows defining mock responses based on input predicates.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents an AI response, which can include a message and/or list of tool invocation requests.static final classFactory methods forTestModelProvider.ToolInvocationRequestinstances that correspond to the internal tools exposed by the autonomous agent runtime to the LLM.static interfaceRepresents an input message.static classstatic final recordRepresents a tool invocation request with a name and arguments.static final recordRepresents a tool result.static final recordRepresents a user message.static classBase class for building reply configurations for specific input predicates.static final classSpecialized reply builder for handling tool result messages.Nested classes/interfaces inherited from interface akka.javasdk.agent.ModelProvider
akka.javasdk.agent.ModelProvider.Anthropic, akka.javasdk.agent.ModelProvider.AzureOpenAi, akka.javasdk.agent.ModelProvider.Bedrock, akka.javasdk.agent.ModelProvider.BedrockPromptCachePlacement, akka.javasdk.agent.ModelProvider.Custom, akka.javasdk.agent.ModelProvider.FromConfig, akka.javasdk.agent.ModelProvider.GoogleAIGemini, akka.javasdk.agent.ModelProvider.HuggingFace, akka.javasdk.agent.ModelProvider.LocalAI, akka.javasdk.agent.ModelProvider.MistralAi, akka.javasdk.agent.ModelProvider.Ollama, akka.javasdk.agent.ModelProvider.OpenAi, akka.javasdk.agent.ModelProvider.VertexAi -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidfixedResponse(TestModelProvider.AiResponse response) Configures a fixedTestModelProvider.AiResponsefor all input messages.voidConfigures a fixed tool invocation response for all input messages.voidfixedResponse(String response) Configures a fixed response for all input messages.voidConfigures a dynamic response for each input message.voidreset()Resets all previously added response configurations.whenMessage(String message) Configures to respond when the content of anTestModelProvider.InputMessageis an exact match of the passedmessage.whenMessage(Predicate<String> predicate) Configures to respond when the passed string predicate matches the content of anTestModelProvider.InputMessage.whenToolResult(TestModelProvider.ToolResult toolResult) Configures to respond when anTestModelProvider.ToolResultis an exact match oftoolResult.whenToolResult(Predicate<TestModelProvider.ToolResult> predicate) Configures to respond when the given predicate matches aTestModelProvider.ToolResult.whenUserMessage(TestModelProvider.UserMessage userMessage) Configures to respond when anTestModelProvider.UserMessageis an exact match ofuserMessage.whenUserMessage(Predicate<TestModelProvider.UserMessage> predicate) Configures to respond when the given predicate matches aTestModelProvider.UserMessage.withMessageSelector(Function<List<TestModelProvider.InputMessage>, TestModelProvider.InputMessage> selector) Configures a custom message selector that determines which input message from the current turn is passed to response predicates.
-
Constructor Details
-
TestModelProvider
public TestModelProvider()
-
-
Method Details
-
modelName
- Specified by:
modelNamein interfaceakka.javasdk.agent.ModelProvider.Custom
-
createChatModel
- Specified by:
createChatModelin interfaceakka.javasdk.agent.ModelProvider.Custom
-
createStreamingChatModel
- Specified by:
createStreamingChatModelin interfaceakka.javasdk.agent.ModelProvider.Custom
-
fixedResponse
Configures a fixed response for all input messages. -
fixedResponse
Configures a fixedTestModelProvider.AiResponsefor all input messages. -
fixedResponse
Configures a fixed tool invocation response for all input messages. -
fixedResponse
public void fixedResponse(Function<TestModelProvider.InputMessage, TestModelProvider.AiResponse> handler) Configures a dynamic response for each input message. -
whenMessage
Configures to respond when the passed string predicate matches the content of anTestModelProvider.InputMessage. The predicate is applied to content ofTestModelProvider.UserMessageorTestModelProvider.ToolResult.Note that to finish the configuration, you must call one of the reply methods.
-
whenMessage
Configures to respond when the content of anTestModelProvider.InputMessageis an exact match of the passedmessage.Note that to finish the configuration, you must call one of the reply methods.
-
whenUserMessage
public TestModelProvider.WhenClause whenUserMessage(Predicate<TestModelProvider.UserMessage> predicate) Configures to respond when the given predicate matches aTestModelProvider.UserMessage. The predicate is applied toTestModelProvider.UserMessageinstances only.Note that to finish the configuration, you must call one of the reply methods.
-
whenUserMessage
Configures to respond when anTestModelProvider.UserMessageis an exact match ofuserMessage.Note that to finish the configuration, you must call one of the reply methods.
-
whenToolResult
public TestModelProvider.WhenToolReplyClause whenToolResult(Predicate<TestModelProvider.ToolResult> predicate) Configures to respond when the given predicate matches aTestModelProvider.ToolResult. The predicate is applied toTestModelProvider.ToolResultinstances only.Note that to finish the configuration, you must call one of the reply methods.
-
whenToolResult
public TestModelProvider.WhenToolReplyClause whenToolResult(TestModelProvider.ToolResult toolResult) Configures to respond when anTestModelProvider.ToolResultis an exact match oftoolResult.Note that to finish the configuration, you must call one of the reply methods.
-
withMessageSelector
public TestModelProvider withMessageSelector(Function<List<TestModelProvider.InputMessage>, TestModelProvider.InputMessage> selector) Configures a custom message selector that determines which input message from the current turn is passed to response predicates. The selector receives all new input messages since the last AI response (tool results and user messages) and returns the one to respond to.The default selector picks the last message.
-
reset
public void reset()Resets all previously added response configurations.
-