Koog 1.0 idioms, gotchas, and scaffolding skills for Kotlin agents on the JVM
88
88%
Does it follow best practices?
Impact
88%
1.95xAverage score across 43 eval scenarios
Passed
No known issues
Process steps in order. Do not skip ahead.
Not all models accept attachments. Quick guide:
GPT4o and later support images. Audio/PDF support varies by exact modelOpus_4_*, Sonnet_4_* accept images and PDFsGemini_2.5_* accept images, video, audioIf the user's chosen model doesn't support the attachment type they want, redirect to a supporting model in the same provider before continuing.
Proceed immediately to Step 2.
The 1.0 prompt DSL exposes an attachments block on user turns:
import ai.koog.prompt.dsl.prompt
import java.io.File
val visionPrompt = prompt("describe-screenshot") {
user(
text = "What's wrong with this UI?",
attachments = listOf(
Attachment.image(File("/path/to/screenshot.png")),
),
)
}Attachment factories cover the common cases:
Attachment.image(file) / Attachment.image(url) / Attachment.image(bytes, mimeType)Attachment.file(file) — for PDF/document support on providers that accept themAttachment.audio(file) — for audio-capable modelsKoog handles provider-specific encoding (base64 inlining vs URL reference vs uploaded-blob references) — you pass the file/bytes/URL, the executor adapts to the provider's wire shape.
Proceed immediately to Step 3.
When attachments come from runtime input (uploads from a Ktor endpoint, file paths from CLI args), build them inside a node body and append to the prompt via llm.writeSession:
val strategy = strategy<File, String>("describe-image") {
val describe by node<File, Message.User>("build-message") { imageFile ->
Message.User(
content = "Describe this image in detail.",
attachments = listOf(Attachment.image(imageFile)),
)
}
val ask by nodeLLMSendMessage()
edge(nodeStart forwardTo describe)
edge(describe forwardTo ask)
edge(ask forwardTo nodeFinish onTextMessage { true })
}For large attachments, prefer URL-based references over inline bytes — base64 inlining inflates request size and counts against token budgets (see add-token-budgeting).
Reference example: examples/simple-examples/.../attachments/ in the repo.
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
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