Koog 1.0 idioms, gotchas, and scaffolding skills for Kotlin agents on the JVM
87
88%
Does it follow best practices?
Impact
87%
1.85xAverage score across 45 eval scenarios
Advisory
Suggest reviewing before use
Process steps in order. Do not skip ahead.
Three overlapping observability layers — pick by purpose:
add-observability) — production signal. GenAI-standard metrics, dashboards, low cardinality. Keep it onhandle-agent-events) — high-level lifecycle callbacks (tool start/end, agent finish, LLM request). Lightweight; good for demos and stdout tracesIf the user wants "production dashboards" → add-observability. "Live stdout demo trace" → handle-agent-events. "I can't figure out why the agent is looping at this edge" → this skill.
Proceed immediately to Step 2.
implementation("ai.koog:agents-features-trace:1.0.0")Consider scoping it to a debug build variant (Gradle debugImplementation for Android, a debug source set for plain JVM) — production binaries don't need this feature on the classpath.
Proceed immediately to Step 3.
import ai.koog.agents.features.trace.Trace
val agent = AIAgent(
promptExecutor = ...,
llmModel = ...,
systemPrompt = "...",
) {
install(Trace) {
// sink — where trace events go
sink = TraceSink.stdout()
// or:
// sink = TraceSink.file(Paths.get("trace.jsonl"))
// or write a custom sink that forwards to a logger
// event filters — drop noisy categories you don't need
includeCategories = setOf(
TraceCategory.NODE_ENTRY,
TraceCategory.NODE_EXIT,
TraceCategory.EDGE_EVALUATION,
TraceCategory.PLANNER_DECISION,
)
}
}The trace feature emits to a sink synchronously — keep the sink fast (stdout, file, in-memory). For a slow sink (network, JSON-formatting per event), wrap it in a buffered/async layer or you'll throttle the agent.
Proceed immediately to Step 4.
A typical trace event line includes: timestamp, category, node name (if applicable), event payload (predicate result, planner choice, LLM token count). Use this to answer questions like:
EDGE_EVALUATION events show the predicate resultPLANNER_DECISION events show the candidates considered and the chosen one with scoreNODE_ENTRY patterns for the same node sequenceCombine with the test mocked-executor pattern (test-koog-agents) to capture a deterministic trace of a known bug — that's the fastest path to a fix.
Proceed immediately to Step 5.
OpenTelemetry also has the word "trace" — it refers to distributed traces (request flow across services). This Koog feature emits internal traces (agent flow inside one process). Both can coexist; they don't compete. If the user mentions "trace" without context, ask whether they want internal diagnostics (this skill) or distributed traces across services (add-observability + OTLP).
Finish here.
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
scenario-15
scenario-16
scenario-17
scenario-18
scenario-19
scenario-20
scenario-21
scenario-22
scenario-23
scenario-24
scenario-25
scenario-26
scenario-27
scenario-28
scenario-29
scenario-30
scenario-31
scenario-32
scenario-33
scenario-34
scenario-35
scenario-36
scenario-37
scenario-38
scenario-39
scenario-40
scenario-41
scenario-42
scenario-43
scenario-44
scenario-45
skills
add-observability
add-persistence
add-rag
add-structured-output
add-token-budgeting
add-tool
cache-llm-calls
define-prompt
domain-model-subtask-pipeline
references
enable-prompt-caching
handle-agent-events
manage-state
migrate-from-0-x
model-planner-subtasks
persist-chat-history
query-sql-from-agent
scaffold-agent
snapshot-and-restore
test-koog-agents
trace-agent-internals
use-attachments
use-functional-agent
use-llm-node-variants
use-planner
wire-a2a
wire-acp-server
wire-ktor-server
wire-mcp-server
wire-spring-boot