mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(context): support skip modules by adding specific moduleName into runningFlowContext
This commit is contained in:
@@ -9,13 +9,14 @@ import work.slhaf.partner.api.agent.factory.component.abstracts.ActivateModel
|
||||
import work.slhaf.partner.api.agent.factory.component.annotation.AgentComponent
|
||||
import work.slhaf.partner.api.agent.factory.component.exception.ModuleFactoryInitFailedException
|
||||
import work.slhaf.partner.api.agent.factory.config.pojo.ModelConfig
|
||||
import work.slhaf.partner.api.agent.factory.context.AgentContext
|
||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext
|
||||
import work.slhaf.partner.api.agent.factory.context.ModuleContextData
|
||||
import java.lang.reflect.Modifier
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
/**
|
||||
* 扫描并实例化 `@AgentComponent` 具体类,写入 [work.slhaf.partner.api.agent.factory.context.AgentContext]。
|
||||
* 扫描并实例化 `@AgentComponent` 具体类,写入 [AgentContext]。
|
||||
*
|
||||
* 行为:
|
||||
* - 若实例是 [AbstractAgentModule],按 Running/Sub/Standalone 构造 `ModuleContextData` 并注册到 modules。
|
||||
@@ -63,7 +64,7 @@ class ComponentRegisterFactory : AgentBaseFactory() {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun registerModule(
|
||||
agentContext: work.slhaf.partner.api.agent.factory.context.AgentContext,
|
||||
agentContext: AgentContext,
|
||||
componentClass: Class<*>,
|
||||
module: AbstractAgentModule,
|
||||
modelConfigMap: Map<String, ModelConfig>,
|
||||
@@ -124,7 +125,7 @@ class ComponentRegisterFactory : AgentBaseFactory() {
|
||||
}
|
||||
|
||||
private fun addAdditionalComponent(
|
||||
agentContext: work.slhaf.partner.api.agent.factory.context.AgentContext,
|
||||
agentContext: AgentContext,
|
||||
componentClass: Class<*>,
|
||||
componentInstance: Any
|
||||
) {
|
||||
|
||||
@@ -65,6 +65,9 @@ object AgentRuntime {
|
||||
coroutineScope {
|
||||
val jobs = modules.map { module ->
|
||||
async {
|
||||
if (runningFlowContext.skippedModules.contains(module.instance.moduleName)) {
|
||||
return@async
|
||||
}
|
||||
module.instance.execute(runningFlowContext)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,17 @@ abstract class RunningFlowContext {
|
||||
val additionalUserInfo: Map<String, String>
|
||||
get() = _additionalUserInfo
|
||||
|
||||
private val _skippedModules = mutableSetOf<String>()
|
||||
val skippedModules: Set<String>
|
||||
get() = _skippedModules
|
||||
|
||||
val status = Status()
|
||||
val info = Info()
|
||||
|
||||
fun addSkippedModule(moduleName: String) {
|
||||
_skippedModules.add(moduleName)
|
||||
}
|
||||
|
||||
fun putUserInfo(key: String, value: String) {
|
||||
_additionalUserInfo[key] = value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user