- Added ModelProfile to the Agent record to allow for more detailed model configurations. - Updated AgentExecutorService to utilize ModelProfile when fetching clients. - Modified BaseAgent interface to include a default modelProfile method. - Adjusted Client interface and implementations to support ModelProfile in conversation and streaming methods. - Enhanced ClientService to retrieve clients based on ModelProfile. - Updated CompletionInterceptor to work with ModelProfile instead of ModelCategory. - Refactored AzureAiClient and other client implementations to handle ModelProfile correctly. - Changed CachedClient to cache responses based on ModelProfile. - Updated ModelCategory to a record type for better validation and immutability. - Enhanced ModelProfile with validation checks for its fields. - Updated ModelProfileService to support fetching profiles based on ModelCategory. - Adjusted tests to accommodate changes in Agent and ModelProfile. - Updated properties files to include category information for model profiles.
90 lines
2.5 KiB
Java
Executable File
90 lines
2.5 KiB
Java
Executable File
package de.extio.lmlib.agent;
|
|
|
|
import java.util.List;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Function;
|
|
|
|
import de.extio.lmlib.agent.responsehandler.AgentResponseHandler;
|
|
import de.extio.lmlib.profile.ModelCategory;
|
|
import de.extio.lmlib.profile.ModelProfile;
|
|
|
|
public record Agent(String name,
|
|
AgentType agentType,
|
|
ModelCategory modelCategory,
|
|
ModelProfile modelProfile,
|
|
String systemPrompt,
|
|
String textTemplate,
|
|
AgentResponseHandler responseHandler,
|
|
Consumer<AgentContext> preProcessor,
|
|
Consumer<AgentContext> postProcessor,
|
|
Function<List<AgentContext>,
|
|
List<AgentContext>> merger,
|
|
Function<AgentContext, AgentNext> chooseNext) implements BaseAgent {
|
|
|
|
public Agent {
|
|
if (name == null) {
|
|
throw new IllegalArgumentException("Name cannot be null");
|
|
}
|
|
if (agentType == null) {
|
|
throw new IllegalArgumentException("Agent type cannot be null");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public AgentType agentType(final AgentContext context) {
|
|
if (agentType != null) {
|
|
return agentType;
|
|
}
|
|
return BaseAgent.super.agentType(context);
|
|
}
|
|
|
|
@Override
|
|
public ModelCategory modelCategory(final AgentContext context) {
|
|
if (modelCategory != null) {
|
|
return modelCategory;
|
|
}
|
|
return BaseAgent.super.modelCategory(context);
|
|
}
|
|
|
|
@Override
|
|
public ModelProfile modelProfile(final AgentContext context) {
|
|
if (modelProfile != null) {
|
|
return modelProfile;
|
|
}
|
|
return BaseAgent.super.modelProfile(context);
|
|
}
|
|
|
|
@Override
|
|
public void preProcess(final AgentContext context) {
|
|
if (preProcessor != null) {
|
|
preProcessor.accept(context);
|
|
}
|
|
BaseAgent.super.preProcess(context);
|
|
}
|
|
|
|
@Override
|
|
public void postProcess(final AgentContext context) {
|
|
if (postProcessor != null) {
|
|
postProcessor.accept(context);
|
|
}
|
|
BaseAgent.super.postProcess(context);
|
|
}
|
|
|
|
@Override
|
|
public List<AgentContext> merge(final List<AgentContext> contexts) {
|
|
if (merger != null) {
|
|
return merger.apply(contexts);
|
|
}
|
|
return BaseAgent.super.merge(contexts);
|
|
}
|
|
|
|
@Override
|
|
public AgentNext chooseNextAgent(final AgentContext context) {
|
|
if (chooseNext != null) {
|
|
return chooseNext.apply(context);
|
|
}
|
|
return BaseAgent.super.chooseNextAgent(context);
|
|
}
|
|
|
|
}
|