agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Feature]: Add Kotlin coroutine extension layer (suspend / Flow APIs)

Open realreus319 opened this issue 11 months ago • 2 comments

Background

agentscope-java exposes many async APIs based on Reactor (Mono / Flux). This works well for Java, but is not idiomatic for Kotlin, where suspend functions and Flow are the standard async model.

Proposal

Add a Kotlin coroutine extension module, e.g.:

agentscope-kotlin

This module would not change the core implementation, but provide Kotlin-friendly APIs on top of the existing Reactor-based core.

Goal

At the API level, convert:

Mono → suspend fun

Flux → Flow

So Kotlin users rarely need to interact with Reactor types directly.

Example suspend fun Agent.send(request: Request): Response fun Agent.streamEvents(): Flow

Internally backed by Mono.awaitSingle() and Flux.asFlow().

Summary

Keep Reactor as the core async implementation

Add a Kotlin coroutine extension layer

Improve Kotlin developer experience without impacting Java users

realreus319 avatar Dec 25 '25 09:12 realreus319

Contribution Welcome!

AlbumenJ avatar Dec 26 '25 08:12 AlbumenJ

I'd like to take this one. @AlbumenJ

Note that agentscope-extensions-kotlin existed on the 1.x branch but was not carried over to 2.0 — the BOM still manages kotlin.version / kotlin.coroutines.version, so the module is simply missing. This would restore it, rebuilt against the 2.0 API rather than a straight port.

Plan:

  1. New module agentscope-extensions/agentscope-extensions-kotlin, registered in agentscope-all and agentscope-bom so Check Module Sync stays green.

  2. Extensions over the non-deprecated 2.0 surface only:

    • CallableAgent.call(...) (Mono) → callSuspend(...) suspend overloads
    • ObservableAgent.observe(...) (Mono) → observeSuspend(...)
    • ReActAgent.streamEvents(...) / HarnessAgent.streamEvents(...) (Flux) → streamEventsFlow(...): Flow

    I plan to skip StreamableAgent.stream(...), since all of its overloads are @Deprecated(since = "2.0.0", forRemoval = true) in favour of streamEvents. Wrapping them would ship a new module built on an API that is scheduled for removal. Happy to include them (deprecated as well) if you'd prefer parity with 1.x.

  3. Naming keeps the 1.x convention (callSuspend / observeSuspend) so 1.x users migrate cleanly. Extension functions cannot reuse the member names — Kotlin resolves member functions before extensions, so agent.call(msg) would always bind to the Mono-returning member.

  4. agentscope-harness will be an optional dependency so the HarnessAgent extensions are available when harness is on the classpath, without forcing it on core-only users.

  5. Unit tests covering value/exception propagation, empty-Mono behaviour, Flow ordering and completion, and cancellation propagating back to the Reactor subscription.

Will keep the change scoped to the new module plus the two distribution registrations.

liulangjietou avatar Aug 05 '26 01:08 liulangjietou