Forge documentation
Kotlin

Kotlin quickstart

A source-correct, no-network first success in Kotlin.

Start with an operation that needs no model, network, identity seed, or wallet. This verifies the actual Kotlin message API before adding a provider or tools.

Prerequisites

The source build uses Kotlin 1.9.22 and JDK 17. Modules use group com.l1fe.forge. Treat Maven publication as a separate verified release step.

Use a source checkout

The paths below assume the Forge checkout is beside your application. Adjust the local path to your workspace. Registry publication is not inferred from the package name.

// In settings.gradle.kts:
includeBuild("../forge/forge-kt")

// In build.gradle.kts (use the source forgeVersion):
dependencies {
    implementation("com.l1fe.forge:forge-core:0.1.0")
}

First success

Save this in your application's entry point after resolving com.l1fe.forge:forge-core.

import com.l1fe.forge.core.ModelMessage
import com.l1fe.forge.core.MessagePart
import com.l1fe.forge.core.Role

fun main() {
    val message = ModelMessage(Role.USER, listOf(MessagePart.Text("Hello, Forge")))
    check(message.textContent() == "Hello, Forge")
    println(message.textContent())
}

Expected output: Hello, Forge. This checks message construction and text extraction only; it does not call an LLM.

Add an agent

AgentConfig takes name, a LanguageModel, tool definitions, executor map, system text, limits, generation options, approval, and telemetry. ToolLoopAgent must be initialized before a run. Use a coroutine scope owned by your application and terminate the agent when done. The default approval object is AutoApprove.

Verify the source

The example uses declarations from the message declarations. Package metadata comes from forge-kt/build.gradle.kts.

Next

On this page