mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(framework): make AgentRuntime.submit blocking and remove runBlocking from AgentInteractionAdapter
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package work.slhaf.partner.api.agent.runtime.interaction
|
package work.slhaf.partner.api.agent.runtime.interaction
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.data.AgentInputData
|
import work.slhaf.partner.api.agent.runtime.interaction.data.AgentInputData
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.data.AgentOutputData
|
import work.slhaf.partner.api.agent.runtime.interaction.data.AgentOutputData
|
||||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.RunningFlowContext
|
import work.slhaf.partner.api.agent.runtime.interaction.flow.RunningFlowContext
|
||||||
@@ -16,9 +15,7 @@ abstract class AgentInteractionAdapter<
|
|||||||
fun submit(inputData: I): O {
|
fun submit(inputData: I): O {
|
||||||
val ctx = parseInputData(inputData)
|
val ctx = parseInputData(inputData)
|
||||||
|
|
||||||
val result = runBlocking {
|
val result = runtime.submit(ctx)
|
||||||
runtime.submit(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
return parseOutputData(result)
|
return parseOutputData(result)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ object AgentRuntime {
|
|||||||
runningModules = buildRunningModules()
|
runningModules = buildRunningModules()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun <C : RunningFlowContext> submit(context: C): C {
|
fun <C : RunningFlowContext> submit(context: C): C = runBlocking {
|
||||||
val deferred = CompletableDeferred<RunningFlowContext>()
|
val deferred = CompletableDeferred<RunningFlowContext>()
|
||||||
channel.send(TurnRequest(context, deferred))
|
channel.send(TurnRequest(context, deferred))
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return deferred.await() as C
|
(return@runBlocking deferred.await() as C)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun executeTurn(
|
private suspend fun executeTurn(
|
||||||
|
|||||||
Reference in New Issue
Block a user