-
Notifications
You must be signed in to change notification settings - Fork 230
feat: add Kotlin coroutine extension layer (Mono -> suspend, Flux -> Flow) #376
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
Merged
AlbumenJ
merged 23 commits into
agentscope-ai:main
from
shlokmestry:feature/kotlin-coroutines-extension
Jan 13, 2026
+179
−0
Merged
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a5b04e7
perf(core): cache sorted hooks and optimize HookNotifier execution
shlokmestry 46b40c4
Refactor hook caching to AgentBase and delegate from ReActAgent
shlokmestry aa8a9f7
Make hooks list immutable and simplify hook mutation API
shlokmestry 17863ba
Merge branch 'main' into feature/optimize-hook-notifier
shlokmestry 0289e3e
refactor: make hooks immutable and unify hook mutation APIs
shlokmestry 1daa413
Merge branch 'main' into feature/optimize-hook-notifier
AlbumenJ b9c8dc7
Move hook caching to AgentBase and remove direct hook mutation
shlokmestry e55459c
feat: add Kotlin coroutine extension layer for Agent APIs
shlokmestry 4fcf75d
Merge branch 'main' into feature/kotlin-coroutines-extension
shlokmestry 285a779
chore: add Apache license header to agentscope-kotlin pom
shlokmestry c0b485f
chore: add Apache license header to AgentExtensions
shlokmestry 4c38b54
Merge branch 'main' into feature/kotlin-coroutines-extension
AlbumenJ 4ce7237
chore: add kotlin coroutine extensions module
shlokmestry bcc2cb9
chore: align kotlin coroutine module with bom and parent poms
shlokmestry 1c26b4f
chore: add Apache 2.0 license headers for kotlin module
shlokmestry a1cfe8e
Merge branch 'main' into feature/kotlin-coroutines-extension
shlokmestry 2fc4a7e
chore: add Apache license headers to Kotlin extension
shlokmestry abf3488
fix: align license headers with repository standard
shlokmestry 0b6f6b7
Merge branch 'main' into feature/kotlin-coroutines-extension
shlokmestry c774812
Remove extra line in pom.xml dependencies section
AlbumenJ cec10b8
Refactor pom.xml by removing unused properties
AlbumenJ 33498ff
Add Kotlin and coroutines versions to pom.xml
AlbumenJ 0a033d5
Fix formatting in pom.xml schemaLocation
AlbumenJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <!-- | ||||||
| ~ Copyright 2024-2025 the original author or authors. | ||||||
| ~ | ||||||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| ~ You may not use this file except in compliance with the License. | ||||||
| ~ You may obtain a copy of the License at | ||||||
| ~ | ||||||
| ~ https://www.apache.org/licenses/LICENSE-2.0 | ||||||
| ~ | ||||||
| ~ Unless required by applicable law or agreed to in writing, software | ||||||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| ~ See the License for the specific language governing permissions and | ||||||
| ~ limitations under the License. | ||||||
| --> | ||||||
|
|
||||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||||||
| http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
|
|
||||||
| <modelVersion>4.0.0</modelVersion> | ||||||
|
|
||||||
| <parent> | ||||||
| <groupId>io.agentscope</groupId> | ||||||
| <artifactId>agentscope-extensions</artifactId> | ||||||
| <version>${revision}</version> | ||||||
| <relativePath>../pom.xml</relativePath> | ||||||
| </parent> | ||||||
|
|
||||||
| <artifactId>agentscope-kotlin</artifactId> | ||||||
|
||||||
| <artifactId>agentscope-kotlin</artifactId> | |
| <artifactId>agentscope-extensions-kotlin</artifactId> |
Outdated
Collaborator
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.
Version should be managed in agentscope-dependencies-bom
94 changes: 94 additions & 0 deletions
94
...cope-extensions/agentscope-kotlin/src/main/kotlin/io/agentscope/kotlin/AgentExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * Copyright 2024-2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
|
|
||
|
|
||
| package io.agentscope.kotlin | ||
|
|
||
| import io.agentscope.core.agent.Agent | ||
| import io.agentscope.core.agent.Event | ||
| import io.agentscope.core.agent.StreamOptions | ||
| import io.agentscope.core.message.Msg | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.reactor.awaitFirstOrNull | ||
| import kotlinx.coroutines.reactor.awaitSingle | ||
| import kotlinx.coroutines.reactive.asFlow | ||
|
|
||
| /* ---------- call(...) -> suspend ---------- */ | ||
|
|
||
| suspend fun Agent.callSuspend(msg: Msg): Msg = | ||
| this.call(msg).awaitSingle() | ||
|
|
||
| suspend fun Agent.callSuspend(msgs: List<Msg>): Msg = | ||
| this.call(msgs).awaitSingle() | ||
|
|
||
| suspend fun Agent.callSuspend(): Msg = | ||
| this.call().awaitSingle() | ||
|
|
||
| suspend fun Agent.callSuspend( | ||
| msg: Msg, | ||
| structuredModel: Class<*> | ||
| ): Msg = | ||
| this.call(msg, structuredModel).awaitSingle() | ||
|
|
||
| suspend fun Agent.callSuspend( | ||
| msgs: List<Msg>, | ||
| structuredModel: Class<*> | ||
| ): Msg = | ||
| this.call(msgs, structuredModel).awaitSingle() | ||
|
|
||
| suspend fun Agent.callSuspend( | ||
| structuredModel: Class<*> | ||
| ): Msg = | ||
| this.call(structuredModel).awaitSingle() | ||
|
|
||
| /* ---------- observe(...) -> suspend ---------- */ | ||
|
|
||
| suspend fun Agent.observeSuspend(msg: Msg) { | ||
| this.observe(msg).awaitFirstOrNull() | ||
| } | ||
|
|
||
| suspend fun Agent.observeSuspend(msgs: List<Msg>) { | ||
| this.observe(msgs).awaitFirstOrNull() | ||
| } | ||
|
|
||
| /* ---------- stream(...) -> Flow ---------- */ | ||
|
|
||
| fun Agent.streamFlow( | ||
| msg: Msg, | ||
| options: StreamOptions = StreamOptions.defaults() | ||
| ): Flow<Event> = | ||
| this.stream(msg, options).asFlow() | ||
|
|
||
| fun Agent.streamFlow( | ||
| msgs: List<Msg>, | ||
| options: StreamOptions = StreamOptions.defaults() | ||
| ): Flow<Event> = | ||
| this.stream(msgs, options).asFlow() | ||
|
|
||
| fun Agent.streamFlow( | ||
| msg: Msg, | ||
| options: StreamOptions, | ||
| structuredModel: Class<*> | ||
| ): Flow<Event> = | ||
| this.stream(msg, options, structuredModel).asFlow() | ||
|
|
||
| fun Agent.streamFlow( | ||
| msgs: List<Msg>, | ||
| options: StreamOptions, | ||
| structuredModel: Class<*> | ||
| ): Flow<Event> = | ||
| this.stream(msgs, options, structuredModel).asFlow() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please revert these changes