Skip to content

Commit 08ce0eb

Browse files
committed
code refactoring
1 parent bc1fd71 commit 08ce0eb

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

examples/src/main/java/com/javaaidev/agenticpatterns/examples/agentastool/RestAPITestCaseGenerationAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected String getPromptTemplate() {
2727
}
2828

2929
@Override
30-
protected void updateRequest(ChatClientRequestSpec spec) {
30+
protected void updateChatClientRequest(ChatClientRequestSpec spec) {
3131
spec.functions("userGenerationAgent");
3232
}
3333

examples/src/main/java/com/javaaidev/agenticpatterns/examples/routingworkflow/CustomerSupportAgent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected String getPromptTemplate() {
7272
}
7373

7474
@Override
75-
protected void updateRequest(ChatClientRequestSpec spec) {
75+
protected void updateChatClientRequest(ChatClientRequestSpec spec) {
7676
spec.system("You are a customer support agent for payment, be polite and helper");
7777
}
7878
}
@@ -100,7 +100,7 @@ protected String getPromptTemplate() {
100100
}
101101

102102
@Override
103-
protected void updateRequest(ChatClientRequestSpec spec) {
103+
protected void updateChatClientRequest(ChatClientRequestSpec spec) {
104104
spec.system("You are a customer support agent for shipping, be polite and helper");
105105
}
106106
}
@@ -128,7 +128,7 @@ protected String getPromptTemplate() {
128128
}
129129

130130
@Override
131-
protected void updateRequest(ChatClientRequestSpec spec) {
131+
protected void updateChatClientRequest(ChatClientRequestSpec spec) {
132132
spec.system(
133133
"You are a customer support agent for general questions, be polite and helper");
134134
}

examples/src/main/java/com/javaaidev/agenticpatterns/examples/taskexecution/UserGenerationAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected String getPromptTemplate() {
2525
}
2626

2727
@Override
28-
protected @Nullable Map<String, Object> getPromptContext(
28+
protected Map<String, Object> getPromptContext(
2929
@Nullable UserGenerationRequest userGenerationRequest) {
3030
var count = AgentUtils.safeGet(userGenerationRequest, UserGenerationRequest::count,
3131
1);

task-execution/src/main/java/com/javaaidev/agenticpatterns/taskexecution/TaskExecutionAgent.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828
public abstract class TaskExecutionAgent<Request, Response> extends Agent implements
2929
Function<Request, Response> {
3030

31-
/**
32-
* Get the prompt template
33-
*
34-
* @return prompt template
35-
*/
36-
protected abstract String getPromptTemplate();
37-
3831
@Nullable
3932
protected Type responseType;
4033

@@ -49,7 +42,7 @@ protected TaskExecutionAgent(ChatClient chatClient, @Nullable Type responseType)
4942
protected TaskExecutionAgent(ChatClient chatClient,
5043
@Nullable ObservationRegistry observationRegistry) {
5144
super(chatClient, observationRegistry);
52-
responseType = TypeResolver.resolveType(this.getClass(), TaskExecutionAgent.class, 1);
45+
this.responseType = TypeResolver.resolveType(this.getClass(), TaskExecutionAgent.class, 1);
5346
}
5447

5548
protected TaskExecutionAgent(ChatClient chatClient, @Nullable Type responseType,
@@ -58,6 +51,13 @@ protected TaskExecutionAgent(ChatClient chatClient, @Nullable Type responseType,
5851
this.responseType = responseType;
5952
}
6053

54+
/**
55+
* Get the prompt template
56+
*
57+
* @return prompt template
58+
*/
59+
protected abstract String getPromptTemplate();
60+
6161
/**
6262
* Prepare for the values of variables in the prompt template
6363
*
@@ -74,7 +74,7 @@ protected Map<String, Object> getPromptContext(@Nullable Request request) {
7474
*
7575
* @param spec {@linkplain ChatClientRequestSpec} from Spring AI
7676
*/
77-
protected void updateRequest(ChatClientRequestSpec spec) {
77+
protected void updateChatClientRequest(ChatClientRequestSpec spec) {
7878
}
7979

8080
@Override
@@ -120,7 +120,7 @@ private Response doCall(@Nullable Request request) {
120120
HashMap::new);
121121
var requestSpec = chatClient.prompt().user(userSpec -> userSpec.text(template)
122122
.params(context));
123-
updateRequest(requestSpec);
123+
updateChatClientRequest(requestSpec);
124124
var responseSpec = requestSpec.call();
125125
Response output;
126126
if (type instanceof Class<?> clazz) {

0 commit comments

Comments
 (0)