Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spring-ai-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<module>spring-ai-mcp</module>
<module>spring-ai-text-to-sql</module>
<module>spring-ai-vector-stores</module>
<module>spring-ai-agentic-patterns</module>
</modules>

</project>
</project>
62 changes: 62 additions & 0 deletions spring-ai-modules/spring-ai-agentic-patterns/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-ai-modules</artifactId>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>spring-ai-agentic-patterns</artifactId>
<name>spring-ai-agentic-patterns</name>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-model</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-client-chat</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<properties>
<java.version>21</java.version>
<spring-ai.version>1.0.2</spring-ai.version>
<spring-boot.version>3.5.5</spring-boot.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.baeldung.springai.agenticpatterns;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.client.ChatClient;

public interface CodeReviewClient extends ChatClient {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.baeldung.springai.agenticpatterns.aimodels;

public final class CodeReviewClientPrompts {

private CodeReviewClientPrompts() {
}

/**
* Prompt for the code review of a given PR
*/
public static final String CODE_REVIEW_PROMPT = """
Given a PR link -> generate a map with proposed code improvements.
The key should be {class-name}:{line-number}:{short-description}.
The value should be the code in one line. For example, 1 proposed improvement could be for the line 'int x = 0, y = 0;':
{"Client:23:'no multiple variables defined in 1 line'", "int x = 0;\\n int y = 0;"}
Rules are, to follow the checkstyle and spotless rules set to the repo. Keep java code clear, readable and extensible.

Finally, if it is not your first attempt, there might feedback provided to you, including your previous suggestion.
You should reflect on it and improve the previous suggestions, or even add more.""";

/**
* Prompt for the evaluation of the result
*/
public static final String EVALUATE_PROPOSED_IMPROVEMENTS_PROMPT = """
Evaluate the suggested code improvements for correctness, time complexity, and best practices.

Return a Map with one entry. The key is the value the evaluation. The value will be your feedback.

The evaluation field must be one of: "PASS", "NEEDS_IMPROVEMENT", "FAIL"
Use "PASS" only if all criteria are met with no improvements needed.
""";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
public class DummyCodeReviewClient implements CodeReviewClient {

@Override
@NonNull
public ChatClientRequestSpec prompt() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull String input) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public Builder mutate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
public class DummyOpsClient implements OpsClient {

@Override
@NonNull
public ChatClientRequestSpec prompt() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull String input) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public Builder mutate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
public class DummyOpsOrchestratorClient implements OpsOrchestratorClient {

@Override
@NonNull
public ChatClientRequestSpec prompt() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull String request) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public Builder mutate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
public class DummyOpsRouterClient implements OpsRouterClient {

@Override
@NonNull
public ChatClientRequestSpec prompt() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull String request) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public ChatClientRequestSpec prompt(@NonNull Prompt prompt) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
@NonNull
public Builder mutate() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.client.ChatClient;

public interface OpsClient extends ChatClient {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.baeldung.springai.agenticpatterns.aimodels;

public final class OpsClientPrompts {

private OpsClientPrompts() {
}

/**
* Array of steps to be taken for the dev pipeline
*/
public static final String[] DEV_PIPELINE_STEPS = {
// Checkout from VCS
"""
Checkout the PR from the link.
If error occurs, return the error,
else return the path of the checked-out code""",
// Build the code and package
"""
Identify the build tool and build the code of the given path.
If error occurs, return the error,
else return the path of the input""",
// Containerize and push to docker repo
"""
On the given path, create the docker container. Then push to our private repo.
If error occurs, return the error,
else return the link of the container and the path to the code""",
// Deploy to test environment
"""
Deploy the given docker image to test.
If error occurs, return the error,
else return the path of the input""",
// Run integration tests
"""
From the PR code, execute the integration tests against test environment.
If error occurs, return the error,
else return success""" };

/**
* Prompt for the deployment of a container to one or many environments
*/
public static final String NON_PROD_DEPLOYMENT_PROMPT =
// Prompt For Deployment
"""
Deploy the given container to the given environment.
If any prod environment is requested, fail.
If error occurs, return the error,
else return success message.""";

/**
* Array of steps to be taken for deployment and test execution against this environment
*/
public static final String[] EXECUTE_TEST_ON_DEPLOYED_ENV_STEPS = {
// Prompt For Deployment. If successful, pass to the next step the PR link and the environment.
"""
Deploy the container associated to the given PR, on the given environment.
If any prod environment is requested, fail.
If error occurs, return the error,
else return an array of strings: '{the PR link] on {the environment}'.""",
// Continue with running the tests from the code base that are related to this env.
// Which means, run the Functional Tests on 'test' env, the Integration Tests on 'int', etc.
"""
Execute the tests from the codebase version provided, that are related to the environment provided.
If error occurs, return the error,
else return the environment as title and then the test outcome.""" };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.client.ChatClient;

public interface OpsOrchestratorClient extends ChatClient {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.baeldung.springai.agenticpatterns.aimodels;

public final class OpsOrchestratorClientPrompts {

private OpsOrchestratorClientPrompts() {
}

/**
* Prompt to identify the environments which the given PR need to be tested on
*/
public static final String REMOTE_TESTING_ORCHESTRATION_PROMPT = """
The user should provide a PR link. From the changes of each PR, you need to decide on which environments
these changes should be tested against. The outcome should be an array of the the PR link and then all the environments.
User input:\s""";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import org.springframework.ai.chat.client.ChatClient;

public interface OpsRouterClient extends ChatClient {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.baeldung.springai.agenticpatterns.aimodels;

import java.util.Map;

public final class OpsRouterClientPrompts {

private OpsRouterClientPrompts() {
}

/**
* Array of available routing options of Ops Model
*/
public static final Map<String, String> OPS_ROUTING_OPTIONS = Map.of(
// option 1: route to run pipeline
"pipeline", """
We'll need make a request to ChainWorkflow. Return only the PR link the user provided""",
// option 2: route to deploy an image in 1 or more envs
"deployment", """
We'll need make a request to ParallelizationWorkflow. Return 3 lines.
First: the container link the user provided, eg 'host/service/img-name/repo:1.12.1'.
Second: the environments, separated with comma, no spaces. eg: 'test,dev,int'
Third: the max concurent workers the client asked for, eg: '3'.""");
}
Loading