feat(agent): support add custom configurable object in Agent launch flow

This commit is contained in:
2026-04-11 21:07:50 +08:00
parent fac6e24e49
commit 94d91d9746
2 changed files with 13 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package work.slhaf.partner; package work.slhaf.partner;
import work.slhaf.partner.common.vector.VectorClientRegistry;
import work.slhaf.partner.framework.agent.Agent; import work.slhaf.partner.framework.agent.Agent;
import work.slhaf.partner.runtime.gateway.WebSocketGatewayRegistration; import work.slhaf.partner.runtime.gateway.WebSocketGatewayRegistration;
@@ -7,6 +8,7 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Agent.newAgent(Main.class) Agent.newAgent(Main.class)
.addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE) .addGatewayRegistration(WebSocketGatewayRegistration.INSTANCE)
.addConfigurable(new VectorClientRegistry())
.launch(); .launch();
} }
} }

View File

@@ -3,11 +3,11 @@ package work.slhaf.partner.framework.agent;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import work.slhaf.partner.framework.agent.config.ConfigCenter; import work.slhaf.partner.framework.agent.config.ConfigCenter;
import work.slhaf.partner.framework.agent.config.Configurable;
import work.slhaf.partner.framework.agent.exception.AgentStartupException; import work.slhaf.partner.framework.agent.exception.AgentStartupException;
import work.slhaf.partner.framework.agent.exception.ExceptionReporter; import work.slhaf.partner.framework.agent.exception.ExceptionReporter;
import work.slhaf.partner.framework.agent.exception.ExceptionReporterHandler; import work.slhaf.partner.framework.agent.exception.ExceptionReporterHandler;
import work.slhaf.partner.framework.agent.factory.AgentRegisterFactory; import work.slhaf.partner.framework.agent.factory.AgentRegisterFactory;
import work.slhaf.partner.framework.agent.factory.component.annotation.AgentComponent;
import work.slhaf.partner.framework.agent.factory.context.AgentContext; import work.slhaf.partner.framework.agent.factory.context.AgentContext;
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistration; import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistration;
import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistry; import work.slhaf.partner.framework.agent.interaction.AgentGatewayRegistry;
@@ -34,6 +34,7 @@ public final class Agent {
private final Class<?> applicationClass; private final Class<?> applicationClass;
private final Set<AgentGatewayRegistration> gatewayRegistrations = new LinkedHashSet<>(); private final Set<AgentGatewayRegistration> gatewayRegistrations = new LinkedHashSet<>();
private final Set<ExceptionReporter> exceptionReporters = new LinkedHashSet<>(); private final Set<ExceptionReporter> exceptionReporters = new LinkedHashSet<>();
private final Set<Configurable> configurables = new LinkedHashSet<>();
private final Set<LifecycleHook> preShutdownHooks = new LinkedHashSet<>(); private final Set<LifecycleHook> preShutdownHooks = new LinkedHashSet<>();
private final Set<LifecycleHook> postShutdownHooks = new LinkedHashSet<>(); private final Set<LifecycleHook> postShutdownHooks = new LinkedHashSet<>();
@@ -46,6 +47,11 @@ public final class Agent {
return this; return this;
} }
public AgentApp addConfigurable(Configurable configurable) {
this.configurables.add(configurable);
return this;
}
public AgentApp addExceptionReporter(ExceptionReporter... exceptionReporters) { public AgentApp addExceptionReporter(ExceptionReporter... exceptionReporters) {
this.exceptionReporters.addAll(Set.of(exceptionReporters)); this.exceptionReporters.addAll(Set.of(exceptionReporters));
return this; return this;
@@ -73,17 +79,17 @@ public final class Agent {
try { try {
// Keep startup order explicit so registries are ready before component scanning. // Keep startup order explicit so registries are ready before component scanning.
for (ExceptionReporter exceptionReporter : exceptionReporters) { for (ExceptionReporter exceptionReporter : exceptionReporters) {
// AgentComponent will be initialized by factory
if (exceptionReporter.getClass().isAnnotationPresent(AgentComponent.class)) {
continue;
}
exceptionReporter.register(); exceptionReporter.register();
} }
// Load class // Load class
StateCenter.INSTANCE.toString(); StateCenter.INSTANCE.toString();
// Register into config center // Register into config center
ModelRuntimeRegistry.INSTANCE.register(); ModelRuntimeRegistry.INSTANCE.register();
AgentGatewayRegistry.INSTANCE.register(); AgentGatewayRegistry.INSTANCE.register();
for (Configurable configurable : configurables) {
configurable.register();
}
for (AgentGatewayRegistration registration : gatewayRegistrations) { for (AgentGatewayRegistration registration : gatewayRegistrations) {
registration.register(); registration.register();