fun handlePrompt()

in agents/agents-test/src/commonMain/kotlin/ai/koog/agents/testing/tools/MockLLMExecutor.kt [147:181]


    fun handlePrompt(prompt: Prompt): List<Message.Response> {
        logger.debug { "Handling prompt with messages:" }
        prompt.messages.forEach { logger.debug { "Message content: ${it.content.take(300)}..." } }

        val lastMessage = getLastMessage(prompt) ?: return responseMatcher.defaultResponse

        // Check the exact response match
        val exactMatchedResponse = findExactResponse(lastMessage, responseMatcher.exactMatches)
        if (exactMatchedResponse != null) {
            logger.debug { "Returning response for exact prompt match: $exactMatchedResponse" }
        }

        // Check partial response match
        val partiallyMatchedResponse =
            if (exactMatchedResponse == null) {
                findPartialResponse(lastMessage, responseMatcher.partialMatches)
                    ?: listOf()
            } else {
                listOf()
            }
        if (partiallyMatchedResponse.any()) {
            logger.debug { "Returning response for partial prompt match: $partiallyMatchedResponse" }
        }

        // Check request conditions
        val conditionals = getConditionalResponse(lastMessage) ?: listOf()

        val result = (exactMatchedResponse ?: listOf()) + partiallyMatchedResponse + conditionals
        if (result.any()) {
            return updateTokenCounts(result, lastMessage.content)
        }

        // Process the default LLM response
        return updateTokenCounts(responseMatcher.defaultResponse, lastMessage.content)
    }