Koog-sauce is a missing ingredient that connects Koog with other frameworks.
- Spring AI Integration - Provides a Koog's
SpringAiLLMClient, which uses Spring AI's ChatClient under the hood. - LangChain4j Integration - Offers
Langchain4jLLMClientfor seamless integration with LangChain4j, supporting both standard and streaming interactions. - AI Agent Builder - Simplifies creation and configuration of AI agents with a fluent builder pattern, making it easy to set up complex agent behaviors.
- JDK 17 or higher
- Gradle 8.14.1 or higher
Add the dependency to your build.gradle.kts file:
dependencies {
// Core library
implementation("me.kpavlov:koog-sauce:[LATEST]")
// For Spring AI integration
implementation("me.kpavlov:koog-sauce-spring-ai:[LATEST]")
implementation("org.springframework.ai:spring-ai-openai:1.0.0")
// For LangChain4j integration
implementation("me.kpavlov:koog-sauce-langchain4j:[LATEST]")
implementation("dev.langchain4j:langchain4j:0.24.0")
implementation("dev.langchain4j:langchain4j-open-ai:0.24.0")
// Koog library
implementation("ai.koog:koog:0.4.0") // or newer
}./gradlew buildOr using the Makefile:
make build// Create Spring AI ChatClient
val chatClient = org.springframework.ai.chat.client.ChatClient.builder(
org.springframework.ai.openai.OpenAiChatModel
.builder()
.openAiApi(
org.springframework.ai.openai.api.OpenAiApi
.builder()
.apiKey("your-api-key")
.build(),
).build(),
).build()
// Create SpringAiLLMClient
val llmClient = me.kpavlov.koog.sauce.spring.ai.chat.SpringAiLLMClient(chatClient)
// Build a prompt using Koog DSL
val prompt = ai.koog.prompt.dsl.Prompt.build("myPrompt") {
system("You are a helpful assistant")
user("Tell me about Kotlin Multiplatform")
}
// Define the model to use
val model = ai.koog.prompt.llm.LLModel(
ai.koog.prompt.llm.LLMProvider.OpenAI,
"gpt-4.1-nano",
listOf(ai.koog.prompt.llm.LLMCapability.Completion),
100500
)
// Execute the prompt
suspend fun executePrompt() {
val responses = llmClient.execute(prompt, model)
// Process the response
val response = responses.first()
println("Response: ${response.content}")
}See the complete example.
// Create LangChain4j ChatModel
val chatModel = dev.langchain4j.model.openai.OpenAiChatModel.builder()
.apiKey("your-api-key")
.modelName("gpt-4")
.build()
// Create Langchain4jLLMClient
val llmClient = me.kpavlov.koog.sauce.langchain4j.Langchain4jLLMClient(chatModel = chatModel)
// Build a prompt using Koog DSL
val prompt = ai.koog.prompt.dsl.Prompt.build("myPrompt") {
system("You are a helpful assistant")
user("Tell me about LangChain4j")
}
// Define the model to use
val model = ai.koog.prompt.llm.LLModel(
ai.koog.prompt.llm.LLMProvider.OpenAI,
"gpt-4",
listOf(ai.koog.prompt.llm.LLMCapability.Completion),
100500,
)
// Execute the prompt
suspend fun executePrompt() {
val responses = llmClient.execute(prompt, model)
println("Response: ${responses.first().content}")
}See the complete example.
// Create a prompt executor
val promptExecutor = ai.koog.prompt.executor.model.PromptExecutor(
llmClient = llmClient,
defaultModel = model
)
// Create an AI agent using the builder
val agent = me.kpavlov.koog.sauce.agents.core.agent.AIAgent<String, String> {
this.promptExecutor = promptExecutor
this.strategy = YourCustomStrategy() // Implement AIAgentStrategy
this.agentConfig = YourAgentConfig() // Implement AIAgentConfigBase
this.toolRegistry = ToolRegistry.builder()
.registerTool(YourCustomTool()) // Add your tools
.build()
}
// Use the agent
suspend fun executeAgent() {
val result = agent.execute("Tell me about Kotlin")
println("Agent result: $result")
}These examples demonstrate how to:
- Integrate with Spring AI and LangChain4j
- Build AI agents with the fluent builder pattern
- Configure different components like prompt executors, strategies, and tools
make build: Build the projectmake test: Run testsmake clean: Clean the projectmake publish: Publish to Maven Localmake doc: Generate KDoc documentationmake help: Show help message
./gradlew testOr using the Makefile:
make testThe project includes comprehensive tests for both Spring AI and LangChain4j integrations:
- Spring AI Tests:
SpringOpenAiTestdemonstrates how to use and test the Spring AI integration with OpenAI models. - LangChain4j Tests:
Langchain4jLLMClientTesttests the standard LangChain4j LLM client functionality.StreamingLangchain4jLLMClientTesttests the streaming capabilities of the LangChain4j LLM client.
These tests serve as additional examples of how to use the integrations in your own projects.
./gradlew dokkaGeneratePublicationHtmlOr using the Makefile:
make docThe documentation is automatically generated and published to GitHub Pages when changes are pushed to the main branch. You can access the latest documentation at:
https://kpavlov.github.io/koog-sauce/
This project is licensed under the MIT License - see the LICENSE file for details.

