MockLLM basics

MockLLM mock = MockLLM.builder()
    .respond("first turn", "Hello, how can I help?")
    .respondWithToolCall("weather in", "weatherTool", Map.of("city", "Bangalore"))
    .respond("weatherTool_result", "It's 28C, sunny.")
    .build();
agent.setModel(mock);
Advertisement

Assert on prompts

MockLLM records every prompt it saw. Assert the agent sent what you expected.

assertThat(mock.calls()).hasSize(2);
assertThat(mock.calls().get(0).systemInstruction()).contains("You are a helpful assistant");
Advertisement

Simulate errors

MockLLM erroring = MockLLM.builder()
    .throwOn("first turn", new LLMException(ErrorKind.QUOTA, "429"))
    .build();
assertThrows(LLMException.class, () -> agent.invoke("first turn"));