refactor(framework): mark AbstractAgentModule as capability holder and consolidate module contracts within abstracts

This commit is contained in:
2026-02-20 15:24:35 +08:00
parent 2a3d33a61e
commit 051b6450e7
2 changed files with 23 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
package work.slhaf.partner.api.agent.factory.module.abstracts package work.slhaf.partner.api.agent.factory.module.abstracts
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityHolder
import work.slhaf.partner.api.agent.factory.module.annotation.Init import work.slhaf.partner.api.agent.factory.module.annotation.Init
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.RunningFlowContext import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.RunningFlowContext
@@ -11,26 +12,23 @@ import work.slhaf.partner.api.chat.pojo.Message
/** /**
* 模块基类 * 模块基类
*/ */
@CapabilityHolder
abstract class AbstractAgentModule { abstract class AbstractAgentModule {
var moduleName: String = javaClass.simpleName var moduleName: String = javaClass.simpleName
interface Running<T : RunningFlowContext> {
fun execute(context: T)
}
interface Sub<I, O> {
fun execute(input: I): O
}
interface Standalone
// TODO 后续于此处扩展生命周期内容
} }
data class Model(
val chatClient: ChatClient,
val chatMessages: MutableList<Message> = mutableListOf(),
val baseMessages: MutableList<Message> = mutableListOf()
)
interface RunningModule<T : RunningFlowContext> {
fun execute(context: T)
}
interface SubModule<I, O> {
fun execute(input: I): O
}
interface StandaloneModule
interface ActivateModel { interface ActivateModel {
companion object { companion object {
@@ -94,12 +92,17 @@ interface ActivateModel {
} }
/** /**
* 对应调用的模型配置名称,默认配合[AbstractAgentModule.moduleName]使用 * 对应调用的模型配置名称
*/ */
fun modelKey(): String { fun modelKey(): String {
return (this as AbstractAgentModule).moduleName return javaClass.simpleName
} }
fun withBasicPrompt(): Boolean fun withBasicPrompt(): Boolean
data class Model(
val chatClient: ChatClient,
val chatMessages: MutableList<Message> = mutableListOf(),
val baseMessages: MutableList<Message> = mutableListOf()
)
} }

View File

@@ -9,7 +9,7 @@ import work.slhaf.partner.api.agent.factory.module.abstracts.AbstractAgentRunnin
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
public class AbstractAgentRunningModuleProxyTest { public class AbstractAgentRunningProxyTest {
@Test @Test
public void test() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException { public void test() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException {
Class<? extends AbstractAgentRunningModule> clazz = new ByteBuddy().subclass(MyAbstractAgentRunningAbstractAgentModule.class) Class<? extends AbstractAgentRunningModule> clazz = new ByteBuddy().subclass(MyAbstractAgentRunningAbstractAgentModule.class)
@@ -18,7 +18,7 @@ public class AbstractAgentRunningModuleProxyTest {
new MyModuleProxyInterceptor() new MyModuleProxyInterceptor()
)) ))
.make() .make()
.load(AbstractAgentRunningModuleProxyTest.class.getClassLoader()) .load(AbstractAgentRunningProxyTest.class.getClassLoader())
.getLoaded(); .getLoaded();
clazz.getConstructor().newInstance().execute(null); clazz.getConstructor().newInstance().execute(null);
} }