mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(framework): rename AgentConfigManager to AgentConfigLoader and update agent/core wiring
This commit is contained in:
@@ -2,7 +2,7 @@ package work.slhaf.partner.api.agent;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.agent.factory.AgentRegisterFactory;
|
||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigLoader;
|
||||
import work.slhaf.partner.api.agent.runtime.exception.AgentExceptionCallback;
|
||||
import work.slhaf.partner.api.agent.runtime.exception.AgentLaunchFailedException;
|
||||
import work.slhaf.partner.api.agent.runtime.exception.GlobalExceptionHandler;
|
||||
@@ -29,7 +29,7 @@ public final class Agent {
|
||||
}
|
||||
|
||||
public interface AgentConfigManagerStep {
|
||||
AgentGatewayStep setAgentConfigManager(Class<? extends AgentConfigManager> agentConfigManager);
|
||||
AgentGatewayStep setAgentConfigManager(Class<? extends AgentConfigLoader> agentConfigManager);
|
||||
}
|
||||
|
||||
public interface AgentGatewayStep {
|
||||
@@ -59,7 +59,7 @@ public final class Agent {
|
||||
private final Class<?> applicationClass;
|
||||
private final CountDownLatch latch = new CountDownLatch(1);
|
||||
private AgentGateway gateway;
|
||||
private Class<? extends AgentConfigManager> agentConfigManagerClass;
|
||||
private Class<? extends AgentConfigLoader> agentConfigManagerClass;
|
||||
private Class<? extends AgentGateway> gatewayClass;
|
||||
private Class<? extends AgentExceptionCallback> agentExceptionCallbackClass;
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class Agent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentGatewayStep setAgentConfigManager(Class<? extends AgentConfigManager> agentConfigManager) {
|
||||
public AgentGatewayStep setAgentConfigManager(Class<? extends AgentConfigLoader> agentConfigManager) {
|
||||
this.agentConfigManagerClass = agentConfigManager;
|
||||
return this;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public final class Agent {
|
||||
|
||||
private void beforeLaunch() {
|
||||
try {
|
||||
AgentConfigManager.setINSTANCE(agentConfigManagerClass.getDeclaredConstructor().newInstance());
|
||||
AgentConfigLoader.setINSTANCE(agentConfigManagerClass.getDeclaredConstructor().newInstance());
|
||||
log.info("配置管理器设置完毕: {}", agentConfigManagerClass.getSimpleName());
|
||||
GlobalExceptionHandler.setExceptionCallback(agentExceptionCallbackClass.getDeclaredConstructor().newInstance());
|
||||
log.info("异常处理回调设置完毕: {}", agentExceptionCallbackClass.getSimpleName());
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
package work.slhaf.partner.api.agent.factory;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.capability.exception.CapabilityFactoryExecuteFailedException;
|
||||
import work.slhaf.partner.api.agent.factory.context.AgentRegisterContext;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public abstract class AgentBaseFactory {
|
||||
public void execute(AgentRegisterContext context) {
|
||||
try {
|
||||
setVariables(context);
|
||||
run();
|
||||
} catch (Exception e) {
|
||||
throw new CapabilityFactoryExecuteFailedException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void setVariables(AgentRegisterContext context);
|
||||
|
||||
protected abstract void run() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException;
|
||||
abstract void execute(AgentRegisterContext context);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import work.slhaf.partner.api.agent.runtime.exception.AgentLaunchFailedException
|
||||
|
||||
public class ConfigFactoryInitFailedException extends AgentLaunchFailedException {
|
||||
public ConfigFactoryInitFailedException(String message, Throwable cause) {
|
||||
super("AgentConfigManager 执行失败: " + message, cause);
|
||||
super("AgentConfigLoader 执行失败: " + message, cause);
|
||||
}
|
||||
|
||||
public ConfigFactoryInitFailedException(String message) {
|
||||
super("AgentConfigManager 执行失败: " + message);
|
||||
super("AgentConfigLoader 执行失败: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class AgentRegisterContext {
|
||||
private Reflections reflections;
|
||||
private CapabilityFactoryContext capabilityFactoryContext = new CapabilityFactoryContext();
|
||||
private ConfigFactoryContext configFactoryContext = new ConfigFactoryContext();
|
||||
private ModuleFactoryContext moduleFactoryContext = new ModuleFactoryContext();
|
||||
private AgentContext agentContext = AgentContext.INSTANCE;
|
||||
|
||||
public AgentRegisterContext(List<URL> urls) {
|
||||
reflections = new Reflections(new ConfigurationBuilder().setScanners(
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import work.slhaf.partner.api.agent.factory.AgentComponent
|
||||
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.AgentConfigLoader
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.entity.RunningFlowContext
|
||||
import work.slhaf.partner.api.chat.ChatClient
|
||||
import work.slhaf.partner.api.chat.constant.ChatConstant
|
||||
@@ -47,7 +47,7 @@ interface ActivateModel {
|
||||
|
||||
companion object {
|
||||
val modelMap: MutableMap<String, Model> = mutableMapOf()
|
||||
private val configManager: AgentConfigManager = AgentConfigManager.INSTANCE
|
||||
private val configManager: AgentConfigLoader = AgentConfigLoader.INSTANCE
|
||||
}
|
||||
|
||||
@Init(order = -1)
|
||||
|
||||
@@ -13,11 +13,11 @@ import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
public abstract class AgentConfigManager {
|
||||
public abstract class AgentConfigLoader {
|
||||
|
||||
private static final String DEFAULT_KEY = "default";
|
||||
@Setter
|
||||
public static AgentConfigManager INSTANCE;
|
||||
public static AgentConfigLoader INSTANCE;
|
||||
protected HashMap<String, ModelConfig> modelConfigMap;
|
||||
protected HashMap<String, List<Message>> modelPromptMap;
|
||||
protected HashMap<String, Boolean> moduleEnabledStatus;
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
* 将从当前运行目录的config文件夹下创建并读取配置
|
||||
*/
|
||||
@Slf4j
|
||||
public class FileAgentConfigManager extends AgentConfigManager {
|
||||
public class FileAgentConfigLoader extends AgentConfigLoader {
|
||||
|
||||
protected static final String CONFIG_DIR = "./config/";
|
||||
protected static final String MODEL_CONFIG_DIR = "./config/model/";
|
||||
@@ -1,7 +1,7 @@
|
||||
package work.slhaf.partner.api.agent.runtime.interaction;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.module.pojo.MetaModule;
|
||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigManager;
|
||||
import work.slhaf.partner.api.agent.runtime.config.AgentConfigLoader;
|
||||
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.flow.AgentRunningFlow;
|
||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
||||
public abstract class AgentInteractionAdapter<I extends AgentInputData, O extends AgentOutputData, C extends RunningFlowContext> {
|
||||
|
||||
protected AgentRunningFlow<C> agentRunningFlow = new AgentRunningFlow<>();
|
||||
protected Map<Integer, List<MetaModule>> moduleOrderedMap = AgentConfigManager.INSTANCE.getModuleOrderedMap();
|
||||
protected Map<Integer, List<MetaModule>> moduleOrderedMap = AgentConfigLoader.INSTANCE.getModuleOrderedMap();
|
||||
|
||||
public C call(C finalInputData) {
|
||||
return agentRunningFlow.launch(moduleOrderedMap, finalInputData);
|
||||
|
||||
Reference in New Issue
Block a user