-
Notifications
You must be signed in to change notification settings - Fork 193
Add Ktor integration via Koog
ktor plugin
#422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note: this is a draft proposal written in examples. Design should be improved and Ktor plugin should be moved as a separate module available in public API if we decide it's worth doing. cc: @e5l WDYT? Can we add this into Ktor marketplace at some point? |
6de7da0
to
a08ba11
Compare
@nomisRev , I've added configuration from yaml/conf file + overriding from DSL. Also created a separate module with the actual plugin. |
Koog
ktor plugin
Qodana for JVM369 new problems were found
@@ Code coverage @@
+ 67% total lines covered
8344 lines analyzed, 5661 lines covered
# Calculated according to the filters of your coverage tool ☁️ View the detailed Qodana report Contact Qodana teamContact us at [email protected]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @Ololoshechkin — these are some great features. Would you be open to splitting the Ktor and Spring Boot integrations into separate PRs, since they represent distinct functionality? Also, do you think it might make sense to refactor the configuration class structure to improve extensibility, and possibly delegate model name mappings to the respective LLM providers?
koog-ktor-plugin/src/commonMain/kotlin/ai/koog/ktor/utils/config/EnvironmentConfigLoader.kt
Outdated
Show resolved
Hide resolved
koog-ktor-plugin/src/commonMain/kotlin/ai/koog/ktor/utils/config/ModelsConfigParser.kt
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
private val OPENAI_MODELS_MAP = mapOf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and others: Let's move it to OpenAI module. Such mappings should live in the provider modules and have no relation to KTor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this definitely needs to be moved but it feels quite impactful to the core core types so I propose to review the code and propose a solution to move this to core in a separate PR to not complicate things further in this PR.
koog-ktor-plugin/src/commonTest/kotlin/ai/koog/ktor/ConfigurationLoadingTest.kt
Outdated
Show resolved
Hide resolved
koog-ktor-plugin/src/commonTest/kotlin/ai/koog/ktor/ModelIdentifierParsingTest.kt
Outdated
Show resolved
Hide resolved
koog-spring-boot-starter/src/main/kotlin/ai/koog/spring/KoogProperties.kt
Outdated
Show resolved
Hide resolved
@kpavlov Hi! Thanks! I only introduced Ktor. But actually you are right -- I should open a PR with kdocs separately and include in the 0.3.0 release |
KDoc is not critical, the config and test structure is more important. Separate PR to refactor this is ok, if you promise to refactor ;) |
@kpavlov yes, I think it can go to 0.4.0, definitely not 0.3.0 :) So this PR is rather a draft that someone would finish while I'm on vacation)) |
@Ololoshechkin, sure. It can be done through the https://github.com/ktorio/ktor-plugin-registry without release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work 👏 👏 👏
I have some critical concerns about some of the API, but I think we can solve this in a subsequent PR as well so I'm not going to block this PR contains the important foundation for the Ktor Koog plugin!
Please let me know in my comments what you think 🙏
examples/src/main/kotlin/ai/koog/agents/example/ktor/KtorIntegrationExample.kt
Outdated
Show resolved
Hide resolved
examples/src/main/kotlin/ai/koog/agents/example/ktor/KtorIntegrationExample.kt
Outdated
Show resolved
Hide resolved
koog-ktor-plugin/src/commonMain/kotlin/ai/koog/ktor/KoogKtorServerPlugin.kt
Outdated
Show resolved
Hide resolved
@Ololoshechkin I can take over if you want 👍 |
@Ololoshechkin @nomisRev can we directly put this in an There is already the Spring integration that is standalone in the the root of the project. I also want to introduce a Redis VectorStore, which will require to move up the current Redis PromptCache in order to introduce an I am not sure if |
Great point! Personally I have no strong opinion on how to organise this. The projects I'm invoked with follow similar strategies but this project seems to have different needs. "integrations/integrations-redis/integrations-redis-shared" could be a good strategy, as in the future we might want to split up the Ktor support into separate modules as well. |
koog-ktor-plugin/src/jvmMain/kotlin/ai/koog/ktor/KoogKtorServerPluginJvm.kt
Outdated
Show resolved
Hide resolved
Koog
ktor pluginKoog
ktor plugin
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…e-using Ktor low-level machinery inside the Koog plugin codebase. - Bump to Ktor 3.2.0 - Rewrite llm, and respond overloads with Koog DSLs.
…build files, tests, and code for consistency. Rewrite AI agent functions with improved parameterization and modularity.
a8fe1a0
to
2282684
Compare
…Ktor library definitions in `libs.versions.toml`.
…pe to run the configuration on until we have suspend plugins in Ktor 4.0
…cope to run the configuration on until we have suspend plugins in Ktor 4.0 - Protect toolRegistry with Mutex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I have a few questions and comments, please take a look
koog-ktor/src/commonMain/kotlin/ai/koog/ktor/utils/EnvConfigLoader.kt
Outdated
Show resolved
Hide resolved
koog-ktor/src/jvmMain/kotlin/ai/koog/ktor/KoogKtorServerPluginJvm.kt
Outdated
Show resolved
Hide resolved
...client/src/commonMain/kotlin/ai/koog/prompt/executor/clients/anthropic/AnthropicLLMClient.kt
Outdated
Show resolved
Hide resolved
...client/src/commonMain/kotlin/ai/koog/prompt/executor/clients/anthropic/AnthropicLLMClient.kt
Outdated
Show resolved
Hide resolved
…d scripts accordingly." This reverts commit b8d3ebc. # Conflicts: # settings.gradle.kts
Revert Ktor Version Catalog Android Example
…via fallback to client settings.
@devcrocod I removed all duplicated default values from the Ktor plugin, and delegate to the defaults from core. I propose to remove the default model, and explicitly require the model when creating an agent. This additional argument will result in a nicer, and type safer API. This would also remove the need for WDYT? |
…configuration structure; remove `defaultLLM` and `agentTools` for better encapsulation.
…factor `aiAgent` to support `suspend`, and encapsulate `scope` in `AgentConfig` for safer concurrency.
…ngs, and ensure explicit `model` parameter usage in AI agent functions.
anthropic.apikey: "your-anthropic-api-key" | ||
google.apikey: "your-google-api-key" | ||
openrouter.apikey: "your-openrouter-api-key" | ||
ollama.enable: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should require a url for Ollama?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It follows the same behavior as the Ollama Koog integration which is the default URL, or ollama.baseUrl = "..."
, or ollama { baseUrl = "..." }
in code.
In my opinion, that’s a reasonable solution |
Thank you for opening a pull request! Please add a brief description of the proposed change here.
Also, please tick the appropriate points in the checklist below.
Type of the change
Checklist for all pull requests
develop
as the base branchAdditional steps for pull requests adding a new feature