Use this path when you want KAI OS as a Kotlin/JVM runtime library instead of starting with the CLI.
The current public example uses a Gradle composite build so it runs directly from this repository without publishing artifacts to Maven first.
./gradlew -p examples/kotlin-runtime-api runThe runnable example lives at examples/kotlin-runtime-api.
It demonstrates:
AgentSpecas a process definition.WorkflowScheduleras a priority-aware DAG scheduler.ToolRegistryas the syscall boundary.ToolCapabilityGrantfor permissioned tool access.SessionMemoryStorewith process and agent memory scopes.LocalWorkerExecutorBackend(parallelism = 2)as a local worker simulation.MockModelProviderfor deterministic, no-key execution.
val memory = SessionMemoryStore()
val runtime = AgentRuntime()
val tools = ToolRegistry(listOf(EchoTool(), MockHttpTool()))
val researcher = agent("researcher") {
memory(memory)
capability(
tool = "mock-http",
permission = ToolPermission.NETWORK,
scope = "mock://kaios/research",
limits = ToolCapabilityLimits(maxCalls = 1),
)
}
val reviewer = agent("reviewer") {
memory(memory)
capability(
tool = "echo",
permission = ToolPermission.ECHO,
limits = ToolCapabilityLimits(maxCalls = 1),
)
}
val flow = workflow("review") {
node("researcher", researcher).priority(20)
node("reviewer", reviewer).dependsOn("researcher")
}
val result = WorkflowScheduler(
runtime = runtime,
modelProvider = MockModelProvider(),
tools = tools,
memory = memory,
executorBackend = LocalWorkerExecutorBackend(parallelism = 2),
).run(flow, "review a payment retry change")
println(result.processes)
println(result.syscalls)The full example prints:
KAI OS Kotlin Runtime API demo
run=run-... workflow=kotlin-runtime-api-review success=true
scheduler backend=local-worker priority=true recovery=true triggers=1
PID AGENT STATE TOKENS MEM SYSCALLS TOOL_MS COST WORKER
1 inspector SUCCEEDED ... ... 1 ... 0 local-worker-...
2 researcher SUCCEEDED ... ... 1 ... 0 local-worker-...
3 reviewer SUCCEEDED ... ... 1 ... 0 local-worker-...
4 validator SUCCEEDED ... ... 1 ... 0 local-worker-...
SYSCALL LEDGER
sys-... pid=... agent=... tool=... allowed=true args=...
The repository smoke check runs this example and asserts that the output includes success=true and SYSCALL LEDGER:
./scripts/repository-ci-smoke.shUse the CLI-first path when you want artifacts, trace files, capsules, and review output on disk. Use the Kotlin API path when you want to embed the runtime model inside a JVM application.