Skip to content

Commit 8106d80

Browse files
committed
code improvement
1 parent a537082 commit 8106d80

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

evaluator-optimizer/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Evaluator-Optimizer Agent
2+
3+
Implementation
4+
of [Evaluator-Optimizer pattern](https://javaaidev.com/docs/agentic-patterns/patterns/evaluator-optimizer)
5+
6+
See [doc](https://javaaidev.com/docs/agentic-patterns/reference-implementation/evaluator-optimizer-agent)

evaluator-optimizer/src/main/java/com/javaaidev/agenticpatterns/evaluatoroptimizer/PromptBasedEvaluatorOptimizerAgent.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ protected PromptBasedEvaluatorOptimizerAgent(ChatClient generationChatClient,
3030
super(generationChatClient, evaluationChatClient, responseType, observationRegistry);
3131
}
3232

33+
/**
34+
* Prompt template for the agent to generate initial result
35+
*
36+
* @return Prompt template
37+
*/
3338
protected abstract String getInitialResultPromptTemplate();
3439

40+
/**
41+
* Prepare for the values of variables in the prompt template to generate initial result
42+
*
43+
* @param request Request
44+
* @return Values of variables
45+
*/
3546
protected @Nullable Map<String, Object> buildInitialResultPromptContext(
3647
@Nullable Request request) {
3748
return new HashMap<>();
@@ -61,8 +72,19 @@ protected TaskExecutionAgent<Request, Response> buildInitialResultAgent(ChatClie
6172
return new GenerateInitialResultAgent(chatClient, responseType, observationRegistry);
6273
}
6374

75+
/**
76+
* Prompt template for the agent to evaluate a result
77+
*
78+
* @return Prompt template
79+
*/
6480
protected abstract String getEvaluationPromptTemplate();
6581

82+
/**
83+
* Prepare for the values of variables in the prompt template to evaluate a result
84+
*
85+
* @param response Response from a previous generation
86+
* @return Values of variables
87+
*/
6688
protected @Nullable Map<String, Object> buildEvaluationPromptContext(
6789
@Nullable Response response) {
6890
return new HashMap<>();
@@ -92,8 +114,19 @@ protected TaskExecutionAgent<Response, Evaluation> buildEvaluationAgent(ChatClie
92114
return new EvaluateAgent(chatClient, observationRegistry);
93115
}
94116

117+
/**
118+
* Prompt template for the agent to optimize a result
119+
*
120+
* @return Prompt template
121+
*/
95122
protected abstract String getOptimizationPromptTemplate();
96123

124+
/**
125+
* Prepare for the values of variables in the prompt template to optimize a result
126+
*
127+
* @param optimizationInput Input for optimization
128+
* @return Values of variables
129+
*/
97130
protected @Nullable Map<String, Object> buildOptimizationPromptContext(
98131
@Nullable OptimizationInput<Response> optimizationInput) {
99132
return new HashMap<>();

examples/src/main/java/com/javaaidev/agenticpatterns/examples/evaluatoroptimizer/CodeGenerationAgent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import org.jspecify.annotations.Nullable;
1111
import org.springframework.ai.chat.client.ChatClient;
1212

13+
/**
14+
* An agent to generate code with evaluation feedbacks
15+
*/
1316
public class CodeGenerationAgent extends
1417
PromptBasedEvaluatorOptimizerAgent<CodeGenerationRequest, CodeGenerationResponse> {
1518

task-execution/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Task Execution
1+
# Task Execution Agent
22

33
Implementation
44
of [Task Execution pattern](https://javaaidev.com/docs/agentic-patterns/patterns/task-execution)

0 commit comments

Comments
 (0)