Overview
Thekoog-spring-boot-starter module provides:
- Auto-configuration: Automatic setup for LLM clients
- Configuration Properties: Easy setup through application.properties/yml
- Conditional Beans: Beans created only when configured
- Dependency Injection: Ready-to-use
SingleLLMPromptExecutorbeans - Multi-provider Support: OpenAI, Anthropic, Google, MistralAI, OpenRouter, DeepSeek, Ollama
- Zero Boilerplate: No manual client configuration
- Spring Native: Works with Spring’s DI and configuration system
- Production Ready: Follows Spring Boot best practices
- Multiple Providers: Configure multiple LLM providers simultaneously
- Type Safe: Full Kotlin type safety and null-safety
Installation
Add the Spring Boot starter dependency:gradle
Configuration
Application Properties
Configure one or more LLM providers in yourapplication.properties:
koog-spring-boot-starter/Module.md:24
YAML Configuration
Or use YAML format inapplication.yml:
Environment Variables
Use environment variables for secure credential management:Basic Usage
Service with Dependency Injection
Inject auto-configured executors into your services:koog-spring-boot-starter/Module.md:72
REST Controller Example
Use agents in Spring Web controllers:koog-spring-boot-starter/Module.md:99
Advanced Usage
Multiple Provider Configuration
Use multiple LLM providers with qualifier annotations:Agent Service with Persistence
Combine with Spring Data for persistent agent sessions:examples/devoxx-belgium-2025/src/main/kotlin/ai/koog/spring/sandwich/agents/KoogAgentService.kt:33
OpenTelemetry Integration
Combine with Spring Boot’s observability features:examples/devoxx-belgium-2025/src/main/kotlin/ai/koog/spring/sandwich/agents/KoogAgentService.kt:58
Testing
Test Configuration
Mock executors in test configurations:koog-spring-boot-starter/Module.md:60
Integration Tests
Test with real executors using test properties:Unit Tests with MockK
Unit test services with mocked dependencies:Auto-configuration Details
Conditional Bean Creation
Beans are created only when configuration is present:Configuration Properties Classes
Type-safe configuration with validation:Configuration Reference
Common Properties
All providers support these properties:| Property | Type | Required | Default | Description |
|---|---|---|---|---|
api-key | String | Yes* | - | API key for authentication |
base-url | String | No | Provider default | Base URL for API endpoint |
Provider-specific Properties
Anthropic
OpenAI
Google Gemini
Ollama (Local)
Best Practices
-
Use Environment Variables: Never commit API keys
-
Profile-specific Configuration: Different configs per environment
-
Nullable Injection: Handle optional providers
-
Health Checks: Monitor LLM availability
Common Use Cases
- REST APIs: AI-powered endpoints
- Scheduled Jobs: Batch processing with agents
- Event-driven Processing: React to Spring events with agents
- Microservices: Agent-powered business logic
- Admin Tools: Internal agent-powered tools
Platform Support
- JVM: Full support
- Spring Boot: 3.x recommended
- Kotlin: 1.9+ recommended
Examples
See complete examples in the repository:examples/spring-boot-kotlin/ and examples/devoxx-belgium-2025/
Next Steps
- Learn about Ktor integration for lightweight web services
- Explore Model Context Protocol for tool integration
- See RAG capabilities for document-based agents
- Check out complete examples