feat: Update responseHandler method to accept AgentContext

This commit is contained in:
extio-de
2025-12-08 22:31:42 +01:00
parent 6b93479b36
commit 55c8e43fb3
4 changed files with 18 additions and 6 deletions

View File

@@ -54,6 +54,14 @@ public record Agent(String name,
return BaseAgent.super.modelProfile(context);
}
@Override
public AgentResponseHandler responseHandler(final AgentContext context) {
if (responseHandler != null) {
return responseHandler;
}
return BaseAgent.super.responseHandler(context);
}
@Override
public void preProcess(final AgentContext context) {
if (preProcessor != null) {

View File

@@ -56,7 +56,7 @@ public interface BaseAgent {
return null;
}
default AgentResponseHandler responseHandler() {
default AgentResponseHandler responseHandler(final AgentContext context) {
return new TextAgentResponseHandler("response");
}
@@ -107,12 +107,12 @@ public interface BaseAgent {
boolean parseable = false;
for (int i = 0; i < 2; i++) {
LOGGER.debug("Conversation: {}", conversation);
LOGGER.debug("Conversation: {}", conversation);
final var responseHandler = this.responseHandler();
final var modelProfile = this.modelProfile(split.context());
final var responseHandler = this.responseHandler(split.context());
long requestStart = 0;
Completion completion = null;
final var requestStart = System.currentTimeMillis();
if (split.context().isStreaming()) {
if (responseHandler instanceof final StreamedAgentResponseHandler streamedResponseHandler) {
streamedResponseHandler.beforeStream(split.context());
@@ -125,17 +125,21 @@ public interface BaseAgent {
}
};
if (modelProfile != null) {
requestStart = System.currentTimeMillis();
completion = client.streamConversation(modelProfile, conversation, chunkConsumer);
}
else {
requestStart = System.currentTimeMillis();
completion = client.streamConversation(this.modelCategory(split.context()), conversation, chunkConsumer);
}
}
else {
if (modelProfile != null) {
requestStart = System.currentTimeMillis();
completion = client.conversation(modelProfile, conversation);
}
else {
requestStart = System.currentTimeMillis();
completion = client.conversation(this.modelCategory(split.context()), conversation);
}
}