Skip to content

Commit d006273

Browse files
author
Yuriy Bezsonov
committed
update demo app flow
1 parent 2630c36 commit d006273

File tree

5 files changed

+79
-78
lines changed

5 files changed

+79
-78
lines changed

samples/spring-ai-te-agent/ai-agent/src/main/java/com/example/ai/agent/service/ChatService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ChatService {
2525
1. Use markdown tables for structured data
2626
2. If unsure, say "I don't know"
2727
3. Use provided context for company policies
28-
4. Use tools for dynamic data (flights, weather, bookings, currency)
28+
4. Use tools for dynamic data (weather, dates, flights, bookings, expenses, currency)
2929
""";
3030

3131
public ChatService(ChatMemoryService chatMemoryService,

samples/spring-ai-te-agent/ai-agent/src/main/java/com/example/ai/agent/tool/DateTimeService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public class DateTimeService {
1111

1212
@Tool(description = """
1313
Get current date and time in specified timezone.
14-
14+
1515
Parameters:
1616
- timeZone: e.g., 'UTC', 'America/New_York', 'Europe/London'
17-
17+
1818
Returns: ISO format (YYYY-MM-DDTHH:MM:SS)
19-
19+
2020
Use this when users mention relative dates like "next week" or "tomorrow".
2121
""")
2222
public String getCurrentDateTime(String timeZone) {

samples/spring-ai-te-agent/demo-scripts/01-create-app.sh

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,39 @@
11
#!/bin/bash
22

3-
# Clear current directory completely
4-
echo "Clearing current directory: $(pwd)"
5-
rm -rf ./*
6-
rm -rf ./.[!.]* 2>/dev/null || true
7-
8-
echo "Checking if spring-boot-cli directory exists and remove it if it does..."
9-
if [ -d "spring-boot-cli" ]; then
10-
echo "Found existing spring-boot-cli directory, removing it..."
11-
rm -rf spring-boot-cli
12-
fi
13-
14-
echo "Downloading Spring Boot CLI 3.5.0..."
15-
curl -L https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-cli/3.5.0/spring-boot-cli-3.5.0-bin.zip -o spring-boot-cli-3.5.0-bin.zip
16-
17-
echo "Creating spring-boot-cli directory..."
18-
mkdir -p spring-boot-cli
19-
20-
echo "Extracting Spring Boot CLI to spring-boot-cli folder..."
21-
unzip -q spring-boot-cli-3.5.0-bin.zip -d spring-boot-cli
22-
23-
echo "Cleaning up zip file..."
24-
rm spring-boot-cli-3.5.0-bin.zip
25-
26-
echo "Spring Boot CLI setup complete!"
27-
echo "You can find the CLI in the spring-boot-cli directory."
3+
pause_and_execute() {
4+
echo ""
5+
echo "About to execute:"
6+
echo "$1"
7+
echo ""
8+
echo "Press any key to continue..."
9+
read -n 1 -s
10+
echo ""
11+
eval "$1"
12+
}
2813

2914
echo "Checking if ai-agent directory exists and remove it..."
3015
if [ -d "ai-agent" ]; then
3116
echo "Found existing ai-agent directory, removing it..."
3217
rm -rf ai-agent
3318
fi
3419

35-
echo ""
36-
echo "About to initialize Spring Boot project with the following command:"
37-
echo -e "\033[1m./spring-boot-cli/spring-3.5.0/bin/spring init --java-version=21 \033[0m"
38-
echo " --build=maven \\"
39-
echo " --packaging=jar \\"
40-
echo " --type=maven-project \\"
41-
echo " --artifact-id=ai.agent \\"
42-
echo " --name=ai-agent \\"
43-
echo " --group-id=com.example \\"
44-
echo -e " \033[1m--dependencies=spring-ai-bedrock-converse,web,thymeleaf \033[0m\\"
45-
echo " --extract \\"
46-
echo " ai-agent"
47-
48-
echo ""
49-
echo "Press any key to continue with Spring initialization..."
50-
read -n 1 -s
51-
52-
echo ""
53-
echo "Initializing Spring Boot project..."
54-
./spring-boot-cli/spring-3.5.0/bin/spring init --java-version=21 \
55-
--build=maven \
56-
--packaging=jar \
57-
--type=maven-project \
58-
--artifact-id=ai.agent \
59-
--name=ai-agent \
60-
--group-id=com.example \
61-
--dependencies=spring-ai-bedrock-converse,web,thymeleaf \
62-
--extract \
63-
ai-agent
20+
pause_and_execute "curl https://start.spring.io/starter.zip \\
21+
-d type=maven-project \\
22+
-d language=java \\
23+
-d bootVersion=3.5.7 \\
24+
-d baseDir=ai-agent \\
25+
-d groupId=com.example \\
26+
-d artifactId=ai-agent \\
27+
-d name=ai-agent \\
28+
-d description='AI Agent with Spring AI and Amazon Bedrock' \\
29+
-d packageName=com.example.ai.agent \\
30+
-d packaging=jar \\
31+
-d javaVersion=21 \\
32+
-d dependencies=spring-ai-bedrock-converse,web,thymeleaf \\
33+
-o ai-agent.zip"
34+
35+
unzip ai-agent.zip
36+
rm ai-agent.zip
6437

6538
echo ""
6639
echo "Initializing Git repository..."
@@ -111,19 +84,15 @@ echo ""
11184
echo "Git status:"
11285
git status
11386

114-
# echo ""
115-
# echo "Opening files in VS Code..."
116-
# code src/main/resources/application.properties
117-
# code pom.xml
118-
# code src/main/java/com/example/ai/agent/ChatService.java
87+
sleep 1
88+
./mvnw clean package
89+
./mvnw spring-boot:run
11990

12091
echo ""
12192
echo "Committing changes to Git repository..."
12293
git add .
12394
git commit -m "Update initial files"
12495

125-
./mvnw spring-boot:run
126-
12796
cp "$SOURCES_FOLDER/demo-scripts/Steps/ChatService.java.1" src/main/java/com/example/ai/agent/service/ChatService.java
12897

12998
./mvnw spring-boot:run

samples/spring-ai-te-agent/demo-scripts/Steps/ChatService.java.5

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ChatService {
2525
1. Use markdown tables for structured data
2626
2. If unsure, say "I don't know"
2727
3. Use provided context for company policies
28-
4. Use tools for dynamic data (flights, weather, bookings)
28+
4. Use tools for dynamic data (weather, dates, flights, bookings)
2929
""";
3030

3131
public ChatService(ChatMemoryService chatMemoryService,
@@ -49,11 +49,6 @@ public class ChatService {
4949
public Flux<String> processChat(String prompt) {
5050
logger.info("Processing chat: '{}'", prompt);
5151
try {
52-
// Simple streaming without memory:
53-
// return chatClient
54-
// .prompt().user(prompt)
55-
// .stream()
56-
// .content();
5752
return chatMemoryService.callWithMemory(chatClient, prompt);
5853
} catch (Exception e) {
5954
logger.error("Error processing chat", e);

samples/spring-ai-te-agent/demo-scripts/demo-flow.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ mkdir spring-ai-agent
77
kiro spring-ai-agent/
88
```
99

10+
We use 4 terminals, open to save time
11+
1012
In the new terminal (Main terminal):
1113

1214
```bash
1315
# git clone https://github.com/aws-samples/java-on-aws.git ./java-on-aws
1416
# export SOURCES_FOLDER=$(pwd)/java-on-aws/samples/spring-ai-te-agent
1517

16-
export SOURCES_FOLDER=../workshops/java-on-aws/samples/spring-ai-te-agent
17-
cd $SOURCES_FOLDER
18+
pushd ../workshops/java-on-aws/samples/spring-ai-te-agent
1819
export SOURCES_FOLDER=$(pwd)
19-
cd ../../../../spring-ai-agent
20+
echo $SOURCES_FOLDER
2021
export AWS_REGION=us-east-1
22+
popd
2123
```
2224

2325
> Ensure AWS credentials are available in this terminal
@@ -65,13 +67,23 @@ In the AI Agent terminal:
6567
$SOURCES_FOLDER/demo-scripts/02-add-memory.sh
6668
```
6769

70+
Show changes in:
71+
72+
- pom.xml
73+
- application.properties
74+
- ChatService
75+
- ChatMemoryService
76+
- ConversationSummaryService
77+
- ChatController
78+
- WebViewController
79+
6880
> In the AI Agent terminal:
6981
7082
```bash
7183
./mvnw spring-boot:test-run
7284
```
7385

74-
Open localhost:8080 in the browser and ask questions:
86+
Open localhost:8080 in the browser, refresh and ask questions:
7587

7688
> My name in Alex
7789
> What is my name?
@@ -89,6 +101,17 @@ Open localhost:8080 in the browser and ask questions:
89101
$SOURCES_FOLDER/demo-scripts/03-add-rag.sh
90102
```
91103

104+
Show changes in:
105+
106+
- pom.xml
107+
- application.properties
108+
- ChatService
109+
- ChatController
110+
- VectorStoreService
111+
- VectorStoreController
112+
113+
Highlight in Terminal output for RAG
114+
92115
> In the AI Agent terminal:
93116
94117
```bash
@@ -100,20 +123,22 @@ $SOURCES_FOLDER/demo-scripts/03-add-rag.sh
100123
```bash
101124
curl -X POST \
102125
-H "Content-Type: text/plain" \
103-
--data-binary @ai-agent/samples/policy-travel.md \
126+
--data-binary @$SOURCES_FOLDER/ai-agent/samples/policy-travel.md \
104127
http://localhost:8080/api/admin/rag-load
105128

106129
curl -X POST \
107130
-H "Content-Type: text/plain" \
108-
--data-binary @ai-agent/samples/policy-expense.md \
131+
--data-binary @$SOURCES_FOLDER/ai-agent/samples/policy-expense.md \
109132
http://localhost:8080/api/admin/rag-load
110133

111134
```
112135

113136
Open localhost:8080 in the browser and ask questions:
114137

115138
> What is our travel policy?
139+
Highlight Europe 130
116140

141+
> What is the weather in Paris tomorrow?
117142
> What is the weather in Las Vegas tomorrow?
118143
119144
`Ctrl+C`
@@ -126,6 +151,11 @@ Open localhost:8080 in the browser and ask questions:
126151
$SOURCES_FOLDER/demo-scripts/04-add-tools.sh
127152
```
128153

154+
Show changes in:
155+
156+
- ChatService
157+
- /tools
158+
129159
> In the AI Agent terminal:
130160
131161
```bash
@@ -134,7 +164,10 @@ $SOURCES_FOLDER/demo-scripts/04-add-tools.sh
134164

135165
Open localhost:8080 in the browser and ask questions:
136166

137-
> What is the weather in Las Vegas tomorrow?
167+
> What is the weather in Paris tomorrow?
168+
169+
> Please find me inbound and outbound flights and accommodations for a trip from London to Paris next week, From Monday to Friday. I travel alone, prefer BA flights in the first part of the day, and choose accommodation which is the most expensive, but comply with our travel policy.
170+
Give me a travel itinerary with flights, accommodation, prices for each day of the travel.
138171

139172
`Ctrl+C`
140173

@@ -168,6 +201,8 @@ cd travel/
168201
./mvnw spring-boot:test-run
169202
```
170203

204+
Highlight in Terminal output for MCP server
205+
171206
Open localhost:8080 in the browser and ask questions:
172207

173208
> Please find me inbound and outbound flights and accommodations for a trip from London to Paris next week, From Monday to Friday. I travel alone, prefer BA flights in the first part of the day, and choose accommodation which is the most expensive, but comply with our travel policy.
@@ -192,6 +227,8 @@ cd backoffice/
192227
./mvnw spring-boot:test-run
193228
```
194229

230+
spring.ai.bedrock.converse.chat.options.cache-options.strategy=SYSTEM_AND_TOOLS
231+
195232
---
196233

197234
## Maintenance Prompt for AI Assistant

0 commit comments

Comments
 (0)