Skip to content

Commit 57233cc

Browse files
authored
Bael 9419 spring ai agentic patterns (#18804)
* [BAEL-9419] Introduce module for spring ai agentic patterns * [BAEL-9419] Introduce the chain-workflow pattern * [BAEL-9419] Introduce the parallelization-workflow pattern * [BAEL-9419] Introduce the routing-workflow pattern * [BAEL-9419] Introduce the orchestrator-workers-workflow pattern * [BAEL-9419] Introduce the evaluator-optimizer-workflow pattern
1 parent a0b841c commit 57233cc

26 files changed

+960
-2
lines changed

spring-ai-modules/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
<module>spring-ai-multiple-llms</module>
2323
<module>spring-ai-text-to-sql</module>
2424
<module>spring-ai-vector-stores</module>
25+
<module>spring-ai-agentic-patterns</module>
2526
</modules>
26-
27-
</project>
27+
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>spring-ai-modules</artifactId>
9+
<version>0.0.1</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>spring-ai-agentic-patterns</artifactId>
14+
<name>spring-ai-agentic-patterns</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.springframework.ai</groupId>
23+
<artifactId>spring-ai-model</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.ai</groupId>
27+
<artifactId>spring-ai-client-chat</artifactId>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
<dependencyManagement>
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.springframework.ai</groupId>
40+
<artifactId>spring-ai-bom</artifactId>
41+
<version>${spring-ai.version}</version>
42+
<type>pom</type>
43+
<scope>import</scope>
44+
</dependency>
45+
</dependencies>
46+
</dependencyManagement>
47+
48+
<properties>
49+
<java.version>21</java.version>
50+
<spring-ai.version>1.0.2</spring-ai.version>
51+
<spring-boot.version>3.5.5</spring-boot.version>
52+
</properties>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-maven-plugin</artifactId>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.springai.agenticpatterns;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
import org.springframework.ai.chat.client.ChatClient;
4+
5+
public interface CodeReviewClient extends ChatClient {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
public final class CodeReviewClientPrompts {
4+
5+
private CodeReviewClientPrompts() {
6+
}
7+
8+
/**
9+
* Prompt for the code review of a given PR
10+
*/
11+
public static final String CODE_REVIEW_PROMPT = """
12+
Given a PR link -> generate a map with proposed code improvements.
13+
The key should be {class-name}:{line-number}:{short-description}.
14+
The value should be the code in one line. For example, 1 proposed improvement could be for the line 'int x = 0, y = 0;':
15+
{"Client:23:'no multiple variables defined in 1 line'", "int x = 0;\\n int y = 0;"}
16+
Rules are, to follow the checkstyle and spotless rules set to the repo. Keep java code clear, readable and extensible.
17+
18+
Finally, if it is not your first attempt, there might feedback provided to you, including your previous suggestion.
19+
You should reflect on it and improve the previous suggestions, or even add more.""";
20+
21+
/**
22+
* Prompt for the evaluation of the result
23+
*/
24+
public static final String EVALUATE_PROPOSED_IMPROVEMENTS_PROMPT = """
25+
Evaluate the suggested code improvements for correctness, time complexity, and best practices.
26+
27+
Return a Map with one entry. The key is the value the evaluation. The value will be your feedback.
28+
29+
The evaluation field must be one of: "PASS", "NEEDS_IMPROVEMENT", "FAIL"
30+
Use "PASS" only if all criteria are met with no improvements needed.
31+
""";
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
import org.springframework.ai.chat.prompt.Prompt;
4+
import org.springframework.lang.NonNull;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class DummyCodeReviewClient implements CodeReviewClient {
9+
10+
@Override
11+
@NonNull
12+
public ChatClientRequestSpec prompt() {
13+
throw new UnsupportedOperationException("Not supported yet.");
14+
}
15+
16+
@Override
17+
@NonNull
18+
public ChatClientRequestSpec prompt(@NonNull String input) {
19+
throw new UnsupportedOperationException("Not supported yet.");
20+
}
21+
22+
@Override
23+
@NonNull
24+
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
25+
throw new UnsupportedOperationException("Not supported yet.");
26+
}
27+
28+
@Override
29+
@NonNull
30+
public Builder mutate() {
31+
throw new UnsupportedOperationException("Not supported yet.");
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
import org.springframework.ai.chat.prompt.Prompt;
4+
import org.springframework.lang.NonNull;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class DummyOpsClient implements OpsClient {
9+
10+
@Override
11+
@NonNull
12+
public ChatClientRequestSpec prompt() {
13+
throw new UnsupportedOperationException("Not supported yet.");
14+
}
15+
16+
@Override
17+
@NonNull
18+
public ChatClientRequestSpec prompt(@NonNull String input) {
19+
throw new UnsupportedOperationException("Not supported yet.");
20+
}
21+
22+
@Override
23+
@NonNull
24+
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
25+
throw new UnsupportedOperationException("Not supported yet.");
26+
}
27+
28+
@Override
29+
@NonNull
30+
public Builder mutate() {
31+
throw new UnsupportedOperationException("Not supported yet.");
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
import org.springframework.ai.chat.prompt.Prompt;
4+
import org.springframework.lang.NonNull;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class DummyOpsOrchestratorClient implements OpsOrchestratorClient {
9+
10+
@Override
11+
@NonNull
12+
public ChatClientRequestSpec prompt() {
13+
throw new UnsupportedOperationException("Not supported yet.");
14+
}
15+
16+
@Override
17+
@NonNull
18+
public ChatClientRequestSpec prompt(@NonNull String request) {
19+
throw new UnsupportedOperationException("Not supported yet.");
20+
}
21+
22+
@Override
23+
@NonNull
24+
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
25+
throw new UnsupportedOperationException("Not supported yet.");
26+
}
27+
28+
@Override
29+
@NonNull
30+
public Builder mutate() {
31+
throw new UnsupportedOperationException("Not supported yet.");
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
import org.springframework.ai.chat.prompt.Prompt;
4+
import org.springframework.lang.NonNull;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class DummyOpsRouterClient implements OpsRouterClient {
9+
10+
@Override
11+
@NonNull
12+
public ChatClientRequestSpec prompt() {
13+
throw new UnsupportedOperationException("Not supported yet.");
14+
}
15+
16+
@Override
17+
@NonNull
18+
public ChatClientRequestSpec prompt(@NonNull String request) {
19+
throw new UnsupportedOperationException("Not supported yet.");
20+
}
21+
22+
@Override
23+
@NonNull
24+
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
25+
throw new UnsupportedOperationException("Not supported yet.");
26+
}
27+
28+
@Override
29+
@NonNull
30+
public Builder mutate() {
31+
throw new UnsupportedOperationException("Not supported yet.");
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.springai.agenticpatterns.aimodels;
2+
3+
import org.springframework.ai.chat.client.ChatClient;
4+
5+
public interface OpsClient extends ChatClient {
6+
}

0 commit comments

Comments
 (0)