Skip to content

Commit ef5df2e

Browse files
committed
refactor: use string block for prompt template
1 parent 7dd851c commit ef5df2e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

agents/src/main/java/dev/langchain4j/Agent.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public Response<AiMessage> execute( Map<String,Object> inputs ) {
3535
}
3636

3737
private PromptTemplate getToolResponseTemplate( ) {
38-
var TEMPLATE_TOOL_RESPONSE = new StringBuilder()
39-
.append("TOOL RESPONSE:").append('\n')
40-
.append("---------------------").append('\n')
41-
.append("{{observation}}").append('\n')
42-
.append( "--------------------" ).append('\n')
43-
.append('\n')
44-
.toString();
38+
var TEMPLATE_TOOL_RESPONSE = """
39+
TOOL RESPONSE:
40+
---------------------
41+
{{observation}}
42+
--------------------
43+
""";
4544
return PromptTemplate.from(TEMPLATE_TOOL_RESPONSE);
4645
}
4746

4847
public Response<AiMessage> execute( String input, List<AgentExecutor.IntermediateStep> intermediateSteps ) {
4948
var agentScratchpadTemplate = getToolResponseTemplate();
50-
var userMessageTemplate = PromptTemplate.from( "USER'S INPUT: {{input}}" ).apply( Map.of( "input", input));
49+
var userMessageTemplate = PromptTemplate.from( "USER'S INPUT: {{input}}" )
50+
.apply( Map.of( "input", input));
5151

5252
var messages = new ArrayList<ChatMessage>();
5353

@@ -58,9 +58,9 @@ public Response<AiMessage> execute( String input, List<AgentExecutor.Intermediat
5858
}
5959

6060
for( AgentExecutor.IntermediateStep step: intermediateSteps ) {
61-
var agentScratchpad = agentScratchpadTemplate.apply( Map.of("observation", step.observation()) );
61+
var agentScratchpad = agentScratchpadTemplate
62+
.apply( Map.of("observation", step.observation()) );
6263
messages.add(new UserMessage(agentScratchpad.text()));
63-
;
6464
}
6565

6666
return chatLanguageModel.generate( messages, tools );

0 commit comments

Comments
 (0)