diff --git a/agentscope-dependencies-bom/pom.xml b/agentscope-dependencies-bom/pom.xml index 96fd30a49..4ea1db4ad 100644 --- a/agentscope-dependencies-bom/pom.xml +++ b/agentscope-dependencies-bom/pom.xml @@ -232,6 +232,20 @@ ${qdrant.version} + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + ${kotlin.coroutines.version} + + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + ${kotlin.coroutines.version} + + + io.milvus @@ -310,9 +324,10 @@ ${a2a-transport-jsonrpc.version} + - redis.clients + redis.clients jedis ${jedis.version} diff --git a/agentscope-extensions/agentscope-kotlin/pom.xml b/agentscope-extensions/agentscope-kotlin/pom.xml new file mode 100644 index 000000000..86d151756 --- /dev/null +++ b/agentscope-extensions/agentscope-kotlin/pom.xml @@ -0,0 +1,67 @@ + + + + + + + 4.0.0 + + + io.agentscope + agentscope-extensions + ${revision} + ../pom.xml + + + agentscope-extensions-kotlin + AgentScope Kotlin Coroutine Extensions + jar + + + + + io.agentscope + agentscope-core + + + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + + + diff --git a/agentscope-extensions/agentscope-kotlin/src/main/kotlin/io/agentscope/kotlin/AgentExtensions.kt b/agentscope-extensions/agentscope-kotlin/src/main/kotlin/io/agentscope/kotlin/AgentExtensions.kt new file mode 100644 index 000000000..b90752dbb --- /dev/null +++ b/agentscope-extensions/agentscope-kotlin/src/main/kotlin/io/agentscope/kotlin/AgentExtensions.kt @@ -0,0 +1,96 @@ + + + + + + +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 = + 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, + 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) { + this.observe(msgs).awaitFirstOrNull() +} + +/* ---------- stream(...) -> Flow ---------- */ + +fun Agent.streamFlow( + msg: Msg, + options: StreamOptions = StreamOptions.defaults() +): Flow = + this.stream(msg, options).asFlow() + +fun Agent.streamFlow( + msgs: List, + options: StreamOptions = StreamOptions.defaults() +): Flow = + this.stream(msgs, options).asFlow() + +fun Agent.streamFlow( + msg: Msg, + options: StreamOptions, + structuredModel: Class<*> +): Flow = + this.stream(msg, options, structuredModel).asFlow() + +fun Agent.streamFlow( + msgs: List, + options: StreamOptions, + structuredModel: Class<*> +): Flow = + this.stream(msgs, options, structuredModel).asFlow() diff --git a/agentscope-extensions/pom.xml b/agentscope-extensions/pom.xml index e5a6dd7d0..d4919d625 100644 --- a/agentscope-extensions/pom.xml +++ b/agentscope-extensions/pom.xml @@ -17,8 +17,11 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + io.agentscope agentscope-parent @@ -26,10 +29,32 @@ ../pom.xml - AgentScope Java - Extensions + io.agentscope agentscope-extensions + AgentScope Java - Extensions pom + + + + 1.9.24 + 1.8.1 + + + + + + + io.agentscope + agentscope-dependencies-bom + ${revision} + pom + import + + + + + agentscope-extensions-a2a agentscope-extensions-autocontext-memory @@ -52,4 +77,5 @@ agentscope-extensions-higress agentscope-extensions-nacos +