Hi folks! Was excited to talk today at JavaOne con...
# koog-agentic-framework
v
Hi folks! Was excited to talk today at JavaOne conference and announce
Koog for Java
. It's been a huge challenge for the whole team but now you can use the same framework seamlessly in both Kotlin and Java projects, with a truly native feel in each. This makes Koog the first major Kotlin framework that was brought to Java K Feel free to share this exciting news with your Java colleagues! Curious how it works? Check out the details šŸ‘‡ https://blog.jetbrains.com/ai/2026/03/koog-comes-to-java/?_cl=MTsxOzE7TGpyMlc2Sld2bHBxOEZHQm1iWEd0UkJTaUtmbDJhQXM3VVhJbnlvcVRLeXVTYkViVlBNS1d5cW9Jb2xpOEF5Wjs=
šŸ™Œ 5
ā˜• 8
kodee happy 2
K 3
kodee intensifies 2
kodee greetings 1
d
[Warning: emotion-triggered post] Hi! That's great to hear! I have some questions though. I just bumped Koog to 0.7.2 in my app, handled the deprecations and I faced some surprises: Koog introduced a JSONObject and a TypeToken which make Tool integration particularly confusing and less Kotlin-idomatic (like KSerializer-based constructors being deprecated). I am wondering whether these introductions are due to the new Java API? If yes, maybe the Java API should have been provided as separate artifacts? Also I already had issues with all the non-suspending Java method additions and I am wondering how much weight it adds to the artifacts? All in all, I feel like us Kotlin developers have been a bit put on the side-bench: Koog is supposed to be 1.0.0-rc at KotlinConf (c.f. Vadim's talk pitch), we never had a public roadmap (or maybe I am wrong here), and we still have important missing stuff (proper support for tools that return structured content, Android and iOS on-device models, etc.). I am sorry if this post appears harsh but I felt this momentum for a few months and needed to voice it. I am of course glad Koog even exists as this is a critical component in my software stack. I am also very grateful for all the work the Koog team put into it: it is a great product despite that Java straying.
v
Hey Didier! Thanks for providing your feedback and sharing your thoughts. As for the Tools API and TypeToken — we can add extra constructors that take KType/KClass everywhere in order to ensure that Kotlin usage still feels native. Actually we tried to do so but maybe missed a few places. cc @Andrey Bragin could you please take a look? At the same time, the internal implementation would remain dependent on TypeTokens and JSONObjects for many reasons and one of them is — supporting non-kotlinx serializers. Even in enterprise Kotlin world many teams use Jackson and not Kotlinx Serialization. So ability to switch is essential. And you know, I also love kotlinx.serialization but that's the state of the ecosystem we have to accept. As for the jar sizes — I think we measured at some point and it wasn't a huge difference between 0.6.4 and 0.7.* — cc @Mark Tkachenko
ā¤ļø 1
non-suspend vs suspend methods and API in general is designed to look and feel natively in both Kotlin and Java. Still Koog remains Kotlin native in many ways but we also made it Java friendly so that language isn't a blocker for teams who haven't yet adopted Kotlin or simply can't do so.
d
> non-suspend vs suspend methods and API in general is designed to look and feel natively in both Kotlin and Java. The overloads
javaXXX()
are visible in auto-completion. Is there a cost on the IDE when you are working on a constrained laptop? I though we could use expect/actuals and have a java-dedicated
java
Kotlin source-sets in addition to the
jvmMain
ones in order to produce dedicated
koog-xxx-java
artifacts.
āž• 2
v
We will think about the artifacts for sure, but as for the auto-completion it usually takes from constant to logarithmic time, and even in the worst case it's a constant addition even if we double the amount of methods. So I would doubt one would be able to feel any difference in real life
a
Koog introduced a JSONObject and a TypeToken which make Tool integration particularly confusing and less Kotlin-idomatic (like KSerializer-based constructors being deprecated).
This is not only related to Java since it allows us to support other serialization frameworks on Kotlin/JVM, as Vadim mentioned. E.g. we got multiple requests to support Jackson, since a lot of teams that do backend with Kotlin use Spring, and Jackson is the default serialization library there. And in general, Jackson is the most popular serialization library on the JVM afaik, so some Kotlin/JVM developers feel weird using another, unfamiliar to them kotlinx.serialization just for Koog. I do understand that it comes with trade-offs though, especially if you are on a pure Kotlin stack and only use kotlinx.serialization. When implementing this new serialization API, we tried making it as simple and familiar to the kotlinx.serialization as possible. Moreover, we provide helper converters between serialization library’s own dynamic JSON objects (
JsonElement
in kotlinx.serialization or
JsonNode
in Jackson) and our own
JSONElement
abstraction. The idea is that you don’t have to interact with Koog’s
JSONElement
manually if you don’t want too, you can convert to/from dynamic JSON objects of your library of choice. That’s what we do internally. You can think of
JSONElement
as an intermediate representation that is serializable with both serialization libraries and allows for serialization-library agnostic implementations were it matters (such as tool args/results). And regarding
TypeToken
, can you elaborate, why is it confusing? The idea was, again, to make it as close to familiar concepts on the Kotlin side as possible. It’s similar to
typeOf<Foo>()
from stdlib that creates a
KType
instance. You can just replace
Foo.serializer()
with
typeToken<Foo>()
in tool constructors and it will work the same as before. It will search for the correct serializer in the
Json.serializersModule
in the
AIAgentConfig.serializer
you specified. And you don’t even have to specify this
serializer
manually, since it’s
KotlinxSerializer()
by default anyway. As a bonus, you can now configure contextual serializers (if you don’t/can’t annotate target classes with
@Serializable
to leverage compiler plugin code generation, e.g. for third-party types) in one place, when setting
AIAgentConfig.serializer
. So you don’t have to keep concrete
KSerializer
instances at hand when constructing a new tool. Here is the doc page describing this serialization API,
JSONElement
interface and supported libraries and converters. https://docs.koog.ai/serialization/#how-features-use-the-serializer. Here are all the available converters for kotlinx.serialization: https://github.com/JetBrains/koog/blob/6e22a66bbc8f1fa39466982312219f3bb80943e3/se[…]tlin/ai/koog/serialization/kotlinx/KotlinxJSONElementMappers.kt So you can do something like this for interop (we’re doing the same thing internally)
Copy code
val koogJson: JSONElement = ... 

val kotlinxJson: JsonElement = koogJson.toKotlinxJsonElement()
// perform some transformations if needed

val updatedKoogJson: JSONElement = kotlinxJson.toKoogJSONElement()
Please let me know if it addresses some of your serialization-related concerns, at least partially, and if you have any suggestions how to make it better
m
As for the jar sizes — I think we measured at some point and it wasn't a huge difference between 0.6.4 and 0.7.*
publishing bundle for 0.6.4 was ~40MB, 0.7.1 was 45MB. Considering a bunch of new modules in 0.7.* it's expected increase.
a
I though we could use expect/actuals and have a java-dedicated
java
Kotlin source-sets in addition to the
jvmMain
ones in order to produce dedicated
koog-xxx-java
artifacts.
We already use expect/actual to provide JVM vs non-JVM APIs. The problem, as I understand it, is that you can’t just put Java code to
java
source set and make it invisible on Kotlin/JVM target. Java code would still be included in the JVM distribution. As for creating completely separate modules, it would be significantly more complex implementation-wise. We would have to reimplement or copy-paste Koog’s core entities (such as LLM session, agent session etc.), which is more error-prone and makes it way harder to maintain. TBH even the current way we implemented it, with expect/actual, already increased complexity and maintenance load a bit. The completion concern is however perfectly valid. I’m afraid there’s no clean way to completely hide Java API methods from Kotlin/JVM code, that’s just how Kotlin works. However, we can try to brainstorm, maybe we would be able to find some neat solutions to make a completion experience better
v
Considering a bunch of new modules in 0.7.*
we added Spring AI integration, Chat Memory, Long-Term Memory — all came with some dependencies of course. 5MB sounds reasonable for all of these. Additionally, you can still depend on individual smaller modules instad of the GOD-module ā€œkoog-agentsā€
šŸ‘ 1
d
@Andrey Bragin thanks a lot for the exhaustive details.
You can think of
JSONElement
as an intermediate representation [...]
So there is an intermediate tree materialized in memory, right? And so if I use an MCP tool, I will deserialize the data from the server with Kotlinx Serialization (via the SDK), Koog will transform the Json tree into a Koog json tree and then serialize it for the model. Am I right?
And regarding
TypeToken
, can you elaborate, why is it confusing?
Because, I wasn't understanding why a tool needed a type token (and a new one). I now understand it is to inform some kind of an equivalent of to serializers module in Koog. Plus we already have KClass and KType. And in my app, I have Kaveriit's TypeToken (Kodein).
v
KClass and KType would change to TypeToken everywhere in Koog Also there’s TypeToken.of which accepts both, and also JavaClass. And also there’s typeToken<T>() function available in Kotlin
d
Oh really? I thought there was only a
typeOf<T>()
... JB really needs to consolidate reflection on KMP. 😊
a
JB really needs to consolidate reflection on KMP
While I partially agree here, there are certain cases when you have to implement your own type token-like type that suits your specific use cases. E.g., in Koog we also have to provide a Java-friendly way to provide type information, so we can’t use
KType
v
I’d actually love to see out-of-the-box tooling/APIs/gradle plugins from the Kotlin team that would help us making API Java-compatible (suspend, kotlinx.serialization, KType, inline reified, extension methods, etc.) so that we wouldn’t have to invent our own šŸ™‚ Maybe one day it would be created. And maybe one day KType would be somehow Java compatible… but not now)