Kotlin agents
Agents contracts and source references for Kotlin.
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.
A bounded run
This complete function accepts a model already configured by the caller. No tools are registered. Supply a model supported by your application and handle the returned error or exception at the caller. This example does not provision provider credentials, identity or deployment.
import com.l1fe.forge.agent.AgentConfig
import com.l1fe.forge.agent.ToolLoopAgent
import com.l1fe.forge.core.LanguageModel
import com.l1fe.forge.core.ModelMessage
import com.l1fe.forge.tool.DenyAll
suspend fun runAgent(model: LanguageModel, messages: List<ModelMessage>) {
val agent = ToolLoopAgent(
AgentConfig(
name = "reader",
model = model,
maxIterations = 3,
approvalHandler = DenyAll("No tools are authorized for this run"),
)
)
agent.initialize()
try {
val output = agent.run(messages)
println(output)
} finally {
agent.terminate()
}
}Kotlin run takes a list of ModelMessage, unlike SDKs whose convenience method takes a prompt string.
Kotlin reference
Each reference records the source path, hash and declaration inventory for this language. Start at the import boundary before using a symbol found in a deeper implementation file.
Lifecycle and failures
Choose finite iteration and token budgets, handle generation and execution failures, and release resources on termination. Inspect the returned usage and completion state before recording a successful run. The SDK health/lifecycle object describes local runtime state; it is not a deployment health check.