simple-examples directory contains over 30 runnable examples demonstrating various Koog framework capabilities. Each example is a complete, working implementation you can run and modify.
Getting Started
Setup
Core Examples
Calculator Agent
A fundamental example demonstrating tool calling, event handling, and agent strategies.- Tool Registry: Type-safe tool registration using annotations
- Agent Strategy: Graph-based execution flow with nodes and edges
- Event Handling: Observing tool calls and agent lifecycle events
- History Compression: Automatic compression when token usage exceeds threshold
Banking Agent with Routing
Demonstrates complex routing between specialized sub-agents for different banking operations. Features:- Classifies user requests (balance inquiry, money transfer, transaction analysis)
- Routes to specialized agents based on classification
- Uses graph-based strategy for routing logic
Advanced Features
Streaming Responses
Stream LLM responses in real-time while executing tools:- Real-time token streaming
- Tool execution during streaming
- HTTP server integration with Ktor
Structured Output
Generate type-safe, schema-validated output from agents:- JSON schemas for validation
- Kotlin data class mapping
- Streaming structured data
- Markdown formatting with schemas
Memory and Persistence
Agents that remember previous interactions:- File Persistence
- SQL Persistence
Observability with OpenTelemetry
Integrate comprehensive tracing and monitoring:- Langfuse for trace visualization
- Weights & Biases Weave
- Custom OpenTelemetry exporters
External API Integration
AWS Bedrock
Use AWS Bedrock models with Koog:Web Search
Agent with web search capabilities:Available Examples
Here’s a quick reference of all available Gradle tasks:Core Examples (Click to expand)
Core Examples (Click to expand)
runExampleCalculator- Basic calculator agentrunExampleCalculatorV2- Enhanced calculatorrunExampleCalculatorLocal- Calculator with local LLMrunExampleGuesser- Number guessing gamerunExampleEssay- Essay writing agent
Banking Examples
Banking Examples
runExampleRoutingViaGraph- Banking with graph routingrunExampleRoutingViaAgentsAsTools- Banking with agents as tools
Structured Output
Structured Output
runExampleStructuredOutputSimple- Basic structured outputrunExampleStructuredOutputAdvancedWithBasicSchema- Advanced basic schemarunExampleStructuredOutputAdvancedWithStandardSchema- Advanced standard schemarunExampleMarkdownStreaming- Streaming MarkdownrunExampleMarkdownStreamingWithTool- Streaming with tools
Streaming
Streaming
runExampleStreamingWithTools- Streaming responses with toolsrunExampleStreamingKtorServer- HTTP server streaming
Persistence
Persistence
runExampleFilePersistentAgent- File-based persistencerunExampleSQLPersistentAgent- SQL database persistence
Observability
Observability
runExampleFeatureOpenTelemetry- OpenTelemetry tracing
External Integration
External Integration
runExampleBedrockAgent- AWS BedrockrunExampleWebSearchAgent- Web searchrunExampleInstagramPostDescriber- Image attachments
Advanced
Advanced
runExampleJokesWithModeration- Content moderationrunExampleExecSandbox- Code execution sandboxrunExampleLoopComponent- Loop-based generationrunExampleFleetProjectTemplateGeneration- Fleet templatesrunExampleRiderProjectTemplate- Rider templates
Interactive Notebooks
Many examples have corresponding Jupyter notebooks for interactive exploration:- Calculator.ipynb - Basic calculator with explanations
- Banking.ipynb - Banking routing patterns
- Chess.ipynb - Chess-playing agent
- OpenTelemetry.ipynb - Observability setup
- Langfuse.ipynb - Langfuse integration
- Weave.ipynb - W&B Weave integration
examples/notebooks/ directory.
Source Code
All examples are available on GitHub:View on GitHub
Browse the complete source code for all simple examples
Next Steps
Code Agent Tutorial
Build a complete coding agent step-by-step
Core Concepts
Learn more about Koog’s architecture