|
| 1 | +[//]: # (title: Kotlin for AI-powered app development) |
| 2 | + |
| 3 | +Kotlin provides a modern and pragmatic foundation for building AI-powered applications. |
| 4 | +It can be used across platforms, integrates well with established AI frameworks, and supports common AI development patterns. |
| 5 | + |
| 6 | +> This page introduces how Kotlin is used in real-world AI scenarios with working examples from |
| 7 | +> the [Kotlin-AI-Examples](https://github.com/Kotlin/Kotlin-AI-Examples) repository. |
| 8 | +> |
| 9 | +{style="note"} |
| 10 | + |
| 11 | +## Kotlin AI agentic framework – Koog |
| 12 | + |
| 13 | +[Koog](https://github.com/JetBrains/koog) is a Kotlin-based framework for creating and running AI agents locally, without requiring external services. |
| 14 | +Koog is JetBrains' innovative, open-source agentic framework that empowers developers to build AI agents within the JVM ecosystem. |
| 15 | +It provides a pure Kotlin implementation for building intelligent agents that can interact with tools, handle complex workflows, and communicate with users. |
| 16 | + |
| 17 | +## More use cases |
| 18 | + |
| 19 | +There are many other use cases where Kotlin can help with AI development. |
| 20 | +From integrating language models into backend services to building AI-powered user interfaces, |
| 21 | +these examples showcase the versatility of Kotlin in various AI applications. |
| 22 | + |
| 23 | +### Retrieval-augmented generation |
| 24 | + |
| 25 | +Use Kotlin to build retrieval-augmented generation (RAG) pipelines that connect language models to external sources like documentation, vector stores, or APIs. |
| 26 | +For example: |
| 27 | + |
| 28 | +* [`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. |
| 29 | +* [`langchain4j-spring-boot`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/langchain4j/langchain4j-spring-boot): A minimal RAG example using LangChain4j. |
| 30 | + |
| 31 | +### Agent-based applications |
| 32 | + |
| 33 | +Build AI agents in Kotlin that reason, plan, and act using language models and tools. |
| 34 | +For example: |
| 35 | + |
| 36 | +* [`koog`](https://github.com/JetBrains/koog): Shows how to use the Kotlin agentic framework Koog to build AI agents. |
| 37 | +* [`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. |
| 38 | + |
| 39 | +### Chain of thought prompting |
| 40 | + |
| 41 | +Implement structured prompting techniques that guide language models through multistep reasoning. |
| 42 | +For example: |
| 43 | + |
| 44 | +* [`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. |
| 45 | + |
| 46 | +### LLMs in backend services |
| 47 | + |
| 48 | +Integrate LLMs into business logic or REST APIs using Kotlin and Spring. |
| 49 | +For example: |
| 50 | + |
| 51 | +* [`spring-ai-examples`](https://github.com/Kotlin/Kotlin-AI-Examples/tree/master/projects/spring-ai/spring-ai-examples): Includes classification, chat, and summarization examples. |
| 52 | +* [`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. |
| 53 | + |
| 54 | +### Multiplatform user interfaces with AI |
| 55 | + |
| 56 | +Use Compose Multiplatform to build interactive AI-powered UIs in Kotlin. |
| 57 | +For example: |
| 58 | + |
| 59 | +* [`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. |
| 60 | + |
| 61 | +## Explore examples |
| 62 | + |
| 63 | +You can explore and run examples from the [Kotlin-AI-Examples](https://github.com/Kotlin/Kotlin-AI-Examples) repository. |
| 64 | +Each project is self-contained. You can use each project as a reference or template for building Kotlin-based AI applications. |
| 65 | + |
| 66 | +## What's next |
| 67 | + |
| 68 | +* Complete the [Build a Kotlin app that uses Spring AI to answer questions based on documents stored in the Qdrant](spring-ai-guide.md) |
| 69 | + tutorial to learn more about using Spring AI with Kotlin in IntelliJ IDEA |
| 70 | +* Join the [Kotlin community](https://kotlinlang.org/community/) to connect with other developers building AI applications with Kotlin |
0 commit comments