Koog, a Kotlin-based framework to build and run Al agents in idiomatic Kotlin

3 days ago 1

Kotlin Alpha Maven Central JetBrains incubator project Kotlin CI status GitHub license docs Slack channel

Koog is a Kotlin-based framework designed to build and run AI agents entirely in idiomatic Kotlin. It lets you create agents that can interact with tools, handle complex workflows, and communicate with users.

Key features of Koog include:

  • Pure Kotlin implementation: Build AI agents entirely in natural and idiomatic Kotlin.
  • MCP integration: Connect to Model Control Protocol for enhanced model management.
  • Embedding capabilities: Use vector embeddings for semantic search and knowledge retrieval.
  • Custom tool creation: Extend your agents with tools that access external systems and APIs.
  • Ready-to-use components: Speed up development with pre-built solutions for common AI engineering challenges.
  • Intelligent history compression: Optimize token usage while maintaining conversation context using various pre-built strategies.
  • Powerful Streaming API: Process responses in real-time with streaming support and parallel tool calls.
  • Persistent agent memory: Enable knowledge retention across sessions and even different agents.
  • Comprehensive tracing: Debug and monitor agent execution with detailed and configurable tracing.
  • Flexible graph workflows: Design complex agent behaviors using intuitive graph-based workflows.
  • Modular feature system: Customize agent capabilities through a composable architecture.
  • Scalable architecture: Handle workloads from simple chatbots to enterprise applications.
  • Multiplatform: Run agents on both JVM and JS targets with Kotlin Multiplatform.

Available LLM providers and platforms

The LLM providers and platforms whose LLMs you can use to power your agent capabilities:

  • Google
  • OpenAI
  • Anthropic
  • OpenRouter
  • Ollama

To help you get started with AI agents, here is a quick example:

fun main() = runBlocking { // Before you run the example, assign a corresponding API key as an environment variable. val apiKey = System.getenv("OPENAI_API_KEY") // or Anthropic, Google, OpenRouter, etc. val agent = simpleSingleRunAgent( executor = simpleOpenAIExecutor(apiKey), // or Anthropic, Google, OpenRouter, etc. systemPrompt = "You are a helpful assistant. Answer user questions concisely.", llmModel = OpenAIModels.Chat.GPT4o ) val result = agent.runAndGetResult("Hello! How can you help me?") println(result) }

Currently, the framework supports the JVM and JS targets.

On JVM, JDK 17 or higher is required to use the framework.

  1. Add dependencies to the build.gradle.kts file:

    dependencies { implementation("ai.koog:koog-agents:0.1.0") }
  2. Make sure that you have mavenCentral() in the list of repositories.

  1. Add dependencies to the build.gradle file:

    dependencies { implementation 'ai.koog:koog-agents:0.1.0' }
  2. Make sure that you have mavenCentral() in the list of repositories.

  1. Add dependencies to the pom.xml file:

    <dependency> <groupId>ai.koog</groupId> <artifactId>koog-agents</artifactId> <version>0.1.0</version> </dependency>
  2. Make sure that you have mavenCentral in the list of repositories.

Read the Contributing Guidelines.

This project and the corresponding community are governed by the JetBrains Open Source and Community Code of Conduct. Please make sure you read it.

Koog is licensed under the Apache 2.0 License.

Please feel free to ask any questions in our official Slack channel (link)

Read Entire Article