Koog,一个基于Kotlin的框架,用于以惯用的Kotlin方式构建和运行AI智能体。
Koog, a Kotlin-based framework to build and run Al agents in idiomatic Kotlin

原始链接: https://github.com/JetBrains/koog

Koog是一个基于Kotlin的AI智能体构建框架,允许开发者使用地道的Kotlin代码创建智能且交互式的应用程序。它具有模型控制协议(MCP)集成、向量嵌入、自定义工具创建以及针对常见AI工程挑战的预构建组件等功能。其关键功能包括智能历史压缩、流式API支持、持久化智能体内存、全面的追踪以及灵活的图工作流程。 Koog支持多种大型语言模型(LLM)提供商,例如OpenAI、Google、Anthropic、OpenRouter和Ollama。该框架采用模块化、可扩展的架构,并通过Kotlin Multiplatform同时支持JVM(JDK 17+)和JS目标平台。 一个简单的示例演示了如何使用系统提示和OpenAI执行器创建智能体。Gradle和Maven的依赖信息也已提供。Koog采用Apache 2.0许可证,其贡献受JetBrains开源和社区行为准则约束。

Hacker News users are discussing Koog, a new Kotlin-based framework from JetBrains for building and running AI agents. One Kotlin developer praises its type-safe, Kotlin-native DSL for creating agents. A key feature highlighted is the seamless swapping between different AI models like OpenAI, Anthropic, and Llama. Smart history compression for token saving, streaming capabilities, and persistent memory hooks are also mentioned as attractive features. The user anticipates testing Koog in a real-world project. Another comment thread, now flagged, seems unrelated to the discussion.

原文

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)

联系我们 contact @ memedata.com