diff --git a/docs/images/spring-boot/get-started-with-koog.svg b/docs/images/spring-boot/get-started-with-koog.svg new file mode 100644 index 00000000000..b372075173f --- /dev/null +++ b/docs/images/spring-boot/get-started-with-koog.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/docs/topics/kotlin-ai-apps-development-overview.md b/docs/topics/kotlin-ai-apps-development-overview.md index 413bbfb303f..95f23093909 100644 --- a/docs/topics/kotlin-ai-apps-development-overview.md +++ b/docs/topics/kotlin-ai-apps-development-overview.md @@ -3,65 +3,95 @@ Kotlin provides a modern and pragmatic foundation for building AI-powered applications. It can be used across platforms, integrates well with established AI frameworks, and supports common AI development patterns. -> This page introduces how Kotlin is used in real-world AI scenarios with working examples from -> the [Kotlin-AI-Examples](https://github.com/Kotlin/Kotlin-AI-Examples) repository. -> -{style="note"} - -## Kotlin AI agentic framework – Koog - -[Koog](https://koog.ai) is a Kotlin-based framework for creating and running AI agents locally, without requiring external services. -Koog is JetBrains' innovative, open-source agentic framework that empowers developers to build AI agents within the JVM ecosystem. -It provides a pure Kotlin implementation for building intelligent agents that can interact with tools, handle complex workflows, and communicate with users. - -## More use cases - -There are many other use cases where Kotlin can help with AI development. -From integrating language models into backend services to building AI-powered user interfaces, -these examples showcase the versatility of Kotlin in various AI applications. - -### Retrieval-augmented generation - -Use Kotlin to build retrieval-augmented generation (RAG) pipelines that connect language models to external sources like documentation, vector stores, or APIs. -For example: - -* [`springAI-demo`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/spring-ai/springAI-demo): A Spring Boot app that loads Kotlin standard library docs into a vector store and supports document-based Q&A. -* [`langchain4j-spring-boot`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/langchain4j/langchain4j-spring-boot): A minimal RAG example using LangChain4j. - -### Agent-based applications - -Build AI agents in Kotlin that reason, plan, and act using language models and tools. -For example: - -* [`koog`](https://github.com/JetBrains/koog): Shows how to use the Kotlin agentic framework Koog to build AI agents. -* [`langchain4j-spring-boot`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/langchain4j/langchain4j-spring-boot): Includes a simple tool-using agent built with LangChain4j. - -### Chain of thought prompting - -Implement structured prompting techniques that guide language models through multistep reasoning. -For example: - -* [`LangChain4j_Overview.ipynb`](https://github.com/Kotlin/Kotlin-AI-Examples/blob/master/notebooks/langchain4j/LangChain4j_Overview.ipynb): A Kotlin Notebook demonstrating chain of thought and structured output. - -### LLMs in backend services - -Integrate LLMs into business logic or REST APIs using Kotlin and Spring. -For example: - -* [`spring-ai-examples`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/spring-ai/spring-ai-examples): Includes classification, chat, and summarization examples. -* [`springAI-demo`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/spring-ai/springAI-demo): Demonstrates full integration of LLM responses with application logic. - -### Multiplatform user interfaces with AI - -Use Compose Multiplatform to build interactive AI-powered UIs in Kotlin. -For example: - -* [`mcp-demo`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/mcp/mcp-demo): A desktop UI that connects to Claude and OpenAI, and presents responses using Compose Multiplatform. - -## Explore examples - -You can explore and run examples from the [Kotlin-AI-Examples](https://github.com/Kotlin/Kotlin-AI-Examples) repository. -Each project is self-contained. You can use each project as a reference or template for building Kotlin-based AI applications. +## Koog + +[Koog](https://koog.ai) is a JetBrains open‑source framework for building AI agents, from simple to complex. +It provides multiplatform support, Spring Boot and Ktor integrations, an idiomatic DSL, +and production‑ready features out of the box. + +### Create a simple agent in a few lines + +```kotlin +fun main() { + runBlocking { + val agent = AIAgent( + // Use Anthropic, Google, OpenRouter, or any other provider + executor = simpleOpenAIExecutor(System.getenv("OPENAI_API_KEY")), + systemPrompt = "You are a helpful assistant. Answer user questions concisely.", + llmModel = OpenAIModels.Chat.GPT4o + ) + + val result = agent.run("Hello! How can you help me?") + println(result) + } +} +``` + +Get started with Koog + +### Key features of Koog + +* **Support for multiplatform development**. Multiplatform support enables agentic application development for JVM, JS, + WasmJS, Android, and iOS. +* **Reliability and fault-tolerance**. With built-in retries, Koog lets developers handle failures such as timeouts or tool errors. + And the agent persistence allows restoring full agent state machines instead of just chat messages. +* **Built-in history compression techniques for long contexts**. Koog comes with advanced strategies to compress and + manage long-running conversations out of the box. +* **Enterprise-ready integrations**. Koog integrates with popular JVM frameworks like Spring Boot and Ktor. +* **Observability with OpenTelemetry exporters**. Koog provides out-of-the-box integration with popular observability providers + such as W&B Weave and Langfuse for monitoring and debugging AI applications. +* **LLM switching and seamless history adaptation**. Koog allows switching to a different LLM with a new set of tools + at any point without losing the existing conversation history. + It also enables rerouting between multiple LLM providers, including OpenAI, Anthropic, Google, and others. + Koog also lets you run agents locally with local models through integration with Ollama. +* **Integration with JVM and Kotlin applications**. Koog provides an idiomatic, type-safe DSL specifically for JVM and Kotlin developers. +* **Model Context Protocol (MCP) integration**. Koog enables the use of MCP tools in agents. +* **Knowledge retrieval and memory**. With embeddings, ranked document storage, and shared agent memory, + Koog enables retaining knowledge across conversations. +* **Streaming capabilities**. Koog lets developers process responses in real-time with streaming support and parallel tool calls. + +### Where to start + +* Explore Koog capabilities in the [Overview](https://docs.koog.ai/). +* Build your first Koog agent with the [Getting started guide](https://docs.koog.ai/single-run-agents/). +* See the latest updates in the [Koog release notes](https://github.com/JetBrains/koog/blob/main/CHANGELOG.md). +* Learn from the [examples](https://docs.koog.ai/examples/). + +## Model Context Protocol (MCP) Kotlin SDK + +The [MCP Kotlin SDK](https://github.com/modelcontextprotocol/kotlin-sdk) is a Kotlin Multiplatform implementation of the Model Context Protocol +that lets developers build AI-powered applications in Kotlin and integrate with LLM surfaces across JVM, WebAssembly (Wasm), and iOS. + +With the MCP Kotlin SDK, you can: + +* Provide context for LLMs in a structured and standardized way, separating context handling from the interaction with LLMs. +* Build MCP clients that consume resources from the existing servers. +* Create MCP servers that expose prompts, tools, and resources for LLMs. +* Use standard communication transports such as stdio, SSE, and WebSocket. +* Handle all MCP protocol messages and lifecycle events. + +## Explore other AI-powered application scenarios + +Thanks to seamless Java interoperability and Kotlin Multiplatform, you can combine Kotlin with established AI SDKs and frameworks, +build backend and desktop/mobile UIs, and adopt patterns like RAG and agent‑based workflows. + +> You can explore and run examples from the [Kotlin-AI-Examples](https://github.com/Kotlin/Kotlin-AI-Examples) repository. +> Each project is self-contained. You can use each project as a reference or template for building Kotlin-based AI applications. + +### Connect to major model providers + +Use Kotlin to connect to major model providers such as OpenAI, Anthropic, Google, and others: + +* [OpenAI](https://github.com/openai/openai-java) — official Java SDK for the OpenAI API. It covers responses and chat, images, and audio. +* [Anthropic (Claude)](https://github.com/anthropics/anthropic-sdk-java) — official Java SDK for the Claude Messages API. It includes modules for Vertex AI and Bedrock integrations. +* [Google AI (Gemini / Vertex AI)](https://github.com/googleapis/java-genai) — official Java SDK with a single client that switches between Gemini API and Vertex AI. +* [Azure OpenAI](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/openai/azure-ai-openai) — official Java client for Azure OpenAI Service. It supports chat completions and embeddings. +* [AWS Bedrock](https://github.com/aws/aws-sdk-kotlin) — official SDKs to invoke foundation models. It includes the Kotlin SDK and Java SDK for Bedrock and Bedrock Runtime. + +### Create retrieval-augmented generation (RAG) piplelines and agent-based apps + +* [Spring AI](https://github.com/spring-projects/spring-ai) — multi-provider abstraction for prompts, chat, embeddings, tools and function calling, and vector stores. +* [LangChain4j](https://docs.langchain4j.dev/tutorials/kotlin/) — JVM toolkit with Kotlin extensions for prompts, tools, RAG pipelines, and agents. ## What's next diff --git a/docs/topics/spring-ai-guide.md b/docs/topics/spring-ai-guide.md index e4ac07f282e..c6c3d7d99d2 100644 --- a/docs/topics/spring-ai-guide.md +++ b/docs/topics/spring-ai-guide.md @@ -1,4 +1,4 @@ -[//]: # (title: Build a Kotlin app that uses Spring AI to answer questions based on documents stored in Qdrant — tutorial) +[//]: # (title: Create a Kotlin app that answers questions with Spring AI — tutorial) In this tutorial, you'll learn how to build a Kotlin app that connects to an LLM via [Spring AI](https://spring.io/projects/spring-ai), stores documents in a vector database, and answers questions using context from those documents.