This page shows the most common first steps with the library.

Agent Framework quickstart (v2.0)#

The fastest way to get something running with Llamatik 2.0 is the Agent { } DSL in :sdk:

import com.llamatik.sdk.framework.*

val agent = Agent {
    systemPrompt("You are a helpful Kotlin assistant.")
    tools { builtIns() }
}

// Single response
val reply = agent.run("Explain Kotlin coroutines in 2 sentences.")
println(reply)

// Streaming
agent.stream("What is a Flow?").collect { chunk ->
    if (chunk is AgentStreamChunk.Delta) print(chunk.text)
}

See the Agent Framework guide for memory, workflows, and custom tools.


Core API quickstart#

Direct use of LlamaBridge (:core) — unchanged from v1.x.

1. Resolve a model path#

import com.llamatik.core.platform.LlamaBridge

val modelPath = LlamaBridge.getModelPath("tinyllama.gguf")

On desktop this is often just a file path. On mobile you may resolve the file from app storage, assets, or a download location.

2. Load a generation model#

val ok = LlamaBridge.initGenerateModel(modelPath)
check(ok) { "Failed to init model at $modelPath" }

3. Generate text#

val text = LlamaBridge.generate("Write a 2 sentence story about a llama.")
println(text)

4. Stream text#

LlamaBridge.generateStream(
    prompt = "Stream a short haiku.",
    callback = object : GenStream {
        override fun onDelta(text: String) = print(text)
        override fun onComplete() = println("\nDone")
        override fun onError(message: String) = println("Error: $message")
    }
)

5. Use embeddings#

val embedModelPath = LlamaBridge.getModelPath("nomic-embed-text.gguf")
val embedOk = LlamaBridge.initEmbedModel(embedModelPath)
check(embedOk) { "Failed to init embedding model" }

val vector: FloatArray = LlamaBridge.embed("hello embeddings")
println("dims = ${vector.size}")

6. Continue a session#

LlamaBridge.initGenerateModel(modelPath)

val answer1 = LlamaBridge.generate("Explain Kotlin coroutines.")
val answer2 = LlamaBridge.generateContinue("Now show a very short example.")

7. Save and restore a session#

val sessionPath = "/tmp/chat.session"

LlamaBridge.sessionSave(sessionPath)
LlamaBridge.sessionLoad(sessionPath)

8. Generate an image#

import com.llamatik.core.platform.StableDiffusionBridge

val sdPath = StableDiffusionBridge.getModelPath("dreamshaper.safetensors")
check(StableDiffusionBridge.initModel(sdPath))

val rgba = StableDiffusionBridge.txt2img(
    prompt = "A watercolor painting of a mountain village"
)
println("Generated bytes = ${rgba.size}")

9. Transcribe audio#

import com.llamatik.core.platform.WhisperBridge

val whisperPath = WhisperBridge.getModelPath("ggml-base.en.bin")
check(WhisperBridge.initModel(whisperPath))

val textResult = WhisperBridge.transcribeWav("/path/to/audio.wav", language = "en")
println(textResult)

From here, move on to the Guides section for more detailed patterns.