Koog Documentation

repository·develop·Indexed 26 days ago

https://github.com/jetbrains/koog

A Kotlin-based framework for building and running AI agents using idiomatic Kotlin and Java APIs. Koog supports multiplatform deployment (JVM, JS, WasmJS, Android, iOS) and provides features for tool interaction, complex workflows, and LLM switching. It includes modules for embeddings via Ollama, a Markdown DSL for prompt generation, and Spring Boot integration through koog-spring-boot-starter and koog-spring-ai adapters.

Tokens
217.3K
Snippets
557
Records
826
Agent score
87%

What's inside Koog

  1. Overview of the rag-vector module

    develop
    The rag-vector module provides vector-based document storage and retrieval capabilities designed for Retrieval-Augmented Generation (RAG) systems. It extends the rag-base module by enabling semantic search and similarity-based retrieval through vector embeddings. Instead of simple keyword matching, it allows for retrieving documents based on their semantic similarity to a query.
  2. Overview of Koog AI Agent Framework

    develop

    Koog is an open-source JetBrains framework for building AI agents specifically for the JVM ecosystem. It supports both Kotlin and Java, providing an idiomatic, type-safe Kotlin DSL and fluent builder-style Java APIs.

    Key capabilities include:

    • Multiplatform Support: Kotlin developers can deploy agents across JS, WasmJS, Android, and iOS targets using Kotlin Multiplatform.
    • Agent Types: Supports basic predefined strategies, functional agents (custom logic via lambdas), graph-based agents (custom workflows), and planner agents (iterative plan execution, beta).
    • Core Components: Management of prompts, agent strategies (directed graphs), tools (external data/service interaction), and extensible features.
    • Advanced Capabilities: History compression, agent persistence, structured output, streaming APIs, knowledge retrieval (RAG/embeddings, beta), tracing, and long-term memory (beta).
    • Integrations: Support for Model Context Protocol (MCP), Spring Boot, Ktor, OpenTelemetry, and the A2A Protocol (beta).
  3. Overview of Koog prompt submodules

    develop

    The prompt module is composed of several specialized submodules:

    • prompt-model: Core data structures and DSL for creating structured prompts.
    • prompt-executor: Components for executing prompts against various language models.
    • prompt-llm: Interfaces and models for language model capabilities and providers.
    • prompt-cache: Caching mechanisms for prompt responses.
    • prompt-markdown: Utilities for working with Markdown in prompts.
    • prompt-structure: Tools for parsing and generating structured data from prompts.
    • prompt-xml: XML handling utilities for prompt content.
  4. Overview of A2A protocol components in Koog

    develop

    Koog implements A2A protocol v0.3.0 through three primary components:

    • A2A Server: An agent or system that exposes an endpoint implementing the A2A protocol. It receives requests, processes tasks, and returns results or status updates. It can function independently of Koog agents.
    • A2A Client: A client application or agent that initiates communication with an A2A server. It can also function independently of Koog agents.
    • A2A Koog Integration: A set of classes and utilities (including A2A features and nodes) designed to integrate A2A seamlessly with Koog Agents.
  5. Overview of Koog features and capabilities

    develop

    Koog is an agentic framework designed for reliability in enterprise environments. It provides tools for building AI agents using advanced algorithms and proven techniques.

    Key Capabilities:

    • Graph Workflows: Model AI workflows as explicit graphs using structured data classes for precise control.
    • History Compression: Built-in strategies to manage long-running conversations and context.
    • Durable Execution: Advanced persistence that allows restoring full agent state machines (including checkpoints and failure recovery) rather than just chat history.
    • Agent Patterns: Native support for Graph workflows, GOAP (Goal-Oriented Action Planning), LLM planning, and multi-agent orchestration.
    • Seamless LLM Switching: Switch LLMs mid-conversation; Koog automatically rewrites history and handles tool availability transitions.
    • Robust Retry Mechanism: Wrap operations in retry components that trigger based on configurable conditions (e.g., timeouts, tool failures, or network issues).
    • Observability: Native OpenTelemetry support with integrations for W&B Weave, Langfuse, and DataDog.
  6. Overview of LLM clients

    develop

    LLM clients in Koog are designed for direct interaction with specific LLM providers. Each client implements the LLMClient interface, providing methods for executing prompts and streaming responses.

    Use an LLM client when working with a single provider and you do not require advanced lifecycle management. If you need to manage multiple providers, use a prompt executor instead.

  7. Overview of Koog Spring AI Integration

    develop

    Koog provides Spring AI integration starters that bridge Spring AI's abstractions (like ChatModel, EmbeddingModel, and VectorStore) with the Koog agent framework. This allows you to use Koog agents, memory, or RAG on top of your existing Spring AI configuration without replacing it.

    Comparison with koog-spring-boot-starter

    Featurekoog-spring-boot-starterkoog-spring-ai starters
    LLM transportKoog's own HTTP clientsDelegates to Spring AI beans (e.g., ChatModel)
    Configurationai.koog.* propertiesspring.ai.* + koog.spring.ai.*
    Use CaseDirect Koog model managementUsing Koog on top of existing Spring AI setup
  8. Overview of Model Context Protocol (MCP) integration

    develop

    The Model Context Protocol (MCP) allows AI agents to interact with external tools and services via a standardized interface. Koog integrates with MCP servers to allow agents to connect to tools, retrieve their definitions, and execute them using arguments provided by an LLM.

    Supported transport protocols:

    • stdio: Used for MCP servers running as separate processes (e.g., Docker containers or CLI tools).
    • SSE (Server-Sent Events): Used for MCP servers running as web services over HTTP.
  9. Overview of Koog Agent Features

    develop

    Koog features allow you to extend and enhance AI agent functionality. You can use features to:

    • Add new capabilities to agents.
    • Intercept and modify agent behavior.
    • Log and monitor agent execution.
    • Register multiple handlers for the same event type within a single feature.

    Built-in features include Event handling, Tracing, Chat memory, Long-term memory, Agent persistence, and OpenTelemetry support.

  10. Overview of OpenTelemetry features in Koog

    develop

    Koog uses OpenTelemetry to provide observability for agentic workflows. The framework automatically instruments the following activities by creating spans:

    • Agent execution: Start and end of the agent's lifecycle.
    • Node execution: Individual steps within the agent's workflow.
    • LLM calls: Requests and responses to Large Language Models.
    • Tool calls: Interactions with external tools or functions.
  11. Overview of the a2a-server module

    develop
    The a2a-server module provides the server-side implementation required to host agents using the A2A protocol. It includes the core A2AServer class for hosting, the AgentExecutor interface for defining custom agent logic, and built-in abstractions for managing sessions, tasks, and push subscriptions.