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

@@ -555,7 +555,7 @@ public class BlogPostAgent implements BaseAgent {
// OPTIONAL: How to parse/store the response (default: TextAgentResponseHandler("response"))
@Override
public AgentResponseHandler responseHandler() {
public AgentResponseHandler responseHandler(final AgentContext ctx) {
return new TextAgentResponseHandler("blogPost");
}

View File

@@ -4,7 +4,7 @@
<artifactId>lm-lib</artifactId>
<groupId>de.extio</groupId>
<name>lm-lib</name>
<version>1.9.0</version>
<version>1.9.2</version>
<properties>
<java.version>21</java.version>

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");
}
@@ -109,10 +109,10 @@ public interface BaseAgent {
for (int i = 0; i < 2; i++) {
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);
}
}