Skip to content

Commit b32b999

Browse files
committed
Codestyle
1 parent b14d70c commit b32b999

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/SpringAiAgenticWorkflowController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.web.bind.annotation.RequestParam;
1212
import org.springframework.web.bind.annotation.RestController;
1313

14+
/** Endpoints for the AgenticWorkflow Service */
1415
@SuppressWarnings("unused")
1516
@RestController
1617
@Slf4j

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/RestaurantMethod.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Locale;
55
import java.util.Map;
66
import javax.annotation.Nonnull;
7+
import lombok.val;
78
import org.springframework.ai.tool.annotation.Tool;
89
import org.springframework.ai.tool.annotation.ToolParam;
910

@@ -29,7 +30,7 @@ record Response(List<String> restaurants) {}
2930
@Tool(description = "Get recommended restaurants for a location")
3031
static RestaurantMethod.Response getRestaurants(
3132
@ToolParam @Nonnull final RestaurantMethod.Request request) {
32-
var recommendations =
33+
val recommendations =
3334
Map.of(
3435
"paris",
3536
List.of("Le Comptoir du Relais", "L'As du Fallafel", "Breizh Café"),

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/SpringAiAgenticWorkflowService.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Objects;
1010
import javax.annotation.Nonnull;
11+
import lombok.extern.slf4j.Slf4j;
1112
import lombok.val;
1213
import org.springframework.ai.chat.client.ChatClient;
1314
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
@@ -18,14 +19,23 @@
1819
import org.springframework.ai.tool.ToolCallbacks;
1920
import org.springframework.stereotype.Service;
2021

22+
/** Service class for the AgenticWorkflow service */
2123
@Service
24+
@Slf4j
2225
public class SpringAiAgenticWorkflowService {
2326
private final ChatModel client = new OrchestrationChatModel();
2427
private final OrchestrationModuleConfig config =
2528
new OrchestrationModuleConfig().withLlmConfig(GPT_4O_MINI);
2629

30+
/**
31+
* Simple agentic workflow using chain-like structure. The agent is generating a travel itinerary
32+
* for a given city.
33+
*
34+
* @param userInput the user input including the target city
35+
* @return a short travel itinerary
36+
*/
2737
@Nonnull
28-
public ChatResponse runAgent(String userInput) {
38+
public ChatResponse runAgent(@Nonnull final String userInput) {
2939

3040
// Configure chat memory
3141
val memory = new InMemoryChatMemory();
@@ -39,32 +49,26 @@ public ChatResponse runAgent(String userInput) {
3949
options.setInternalToolExecutionEnabled(true);
4050

4151
// Prompts for the chain workflow
42-
List<String> systemPrompts =
52+
final List<String> systemPrompts =
4353
List.of(
4454
"You are a traveling planning agent for a single day trip. Where appropriate, use the provided tools. First, start by suggesting some restaurants for the mentioned city.",
4555
"Now, check the whether for the city.",
4656
"Finally, combine the suggested itinerary from this conversation into a short, one-sentence plan for the day trip.");
4757

4858
// Perform the chain workflow
49-
int step = 0;
5059
String responseText = userInput;
5160
ChatResponse response = null;
5261

53-
System.out.printf("\nSTEP %s:\n %s%n", step++, responseText);
54-
55-
for (String systemPrompt : systemPrompts) {
62+
for (final String systemPrompt : systemPrompts) {
5663

5764
// Combine the pre-defined prompt with the previous answer to get the new input
58-
String input = String.format("{%s}\n {%s}", systemPrompt, responseText);
65+
val input = String.format("{%s}\n {%s}", systemPrompt, responseText);
5966
val prompt = new Prompt(input, options);
6067

6168
// Make a call to the LLM with the new input
6269
response =
63-
Objects.requireNonNull(
64-
cl.prompt(prompt).call().chatResponse(), "Chat response is null in step " + step);
70+
Objects.requireNonNull(cl.prompt(prompt).call().chatResponse(), "Chat response is null.");
6571
responseText = response.getResult().getOutput().getText();
66-
67-
System.out.printf("\nSTEP %s:\n %s%n", step++, responseText);
6872
}
6973

7074
return response;

0 commit comments

Comments
 (0)