Kest

Search

Search the documentation

AI

Overview

Use language models from your services: chat, tools, agents, search by meaning, and tests.

A large language model (LLM) such as Claude takes text and produces text. Your application can use one to summarise a support ticket, answer a customer, extract data from a document, or decide which of your functions to call. The ai package gives you the pieces, in the same style as the rest of Kest, with no extra SDK:

ConceptIn plain wordsKest
Modelthe LLM you call over HTTPChatModel: AnthropicModel, OpenAiCompatibleModel
Toola function of yours the model may ask you to run (look up an order)@AiTool
Agenta loop: ask the model, run the tools it requests, ask again, until it answersAgent
Embeddingtext turned into numbers so similar meanings are closeEmbeddingModel, KnowledgeBase
Test modela fake model with scripted repliesFakeChatModel
Loading diagram…
Kest.run<AppModule> {
    import(AiModule.forRoot {
        model = AnthropicModel(apiKey = System.getenv("ANTHROPIC_API_KEY"))                // or OpenAiCompatibleModel(...)
        embeddings = OpenAiEmbeddings(apiKey = System.getenv("OPENAI_API_KEY"))
    })
}
 
@Injectable class Support(private val ai: AiService) {
    fun answer(q: String): String = ai.chat(q, system = "You are a polite support agent for Acme Shop.")
}

AiService gives you chat(prompt, system), agent(...) (a model that can use your methods as tools) and knowledgeBase() (search by meaning).

Page
ModelsAnthropic, OpenAI-compatible (OpenAI, Ollama, vLLM, ...) and the ChatModel interface
Tools@AiTool: let a model call your methods
Agentsthe loop that runs tools until there is an answer, with limits
Embeddingssearch by meaning, and answering from your own documents
Testinga fake model, so tests need no network and cost nothing

Things to know before you build

  • A model answers from text; it does not know your data unless you give it. Two ways to give it data: tools (it asks for what it needs) and retrieval (you search your documents first and put the best passages in the prompt).
  • Models make mistakes and can be fooled by text in the data they read (prompt injection). Treat model output as untrusted input: validate it, never run it as code or SQL, and limit what tools can do.
  • Cost and speed: every call costs money and takes seconds. Cache, keep prompts short, use maxTokens, and run long work in a queue rather than inside a web request.
  • Keep the API key in the environment, never in code.

Everything talks to the providers over plain HTTP. Streaming responses are not built: chat returns the whole reply.

Read more