Skip to content

Commit ad52730

Browse files
committed
Rename Agent classes to use ChatBot
1 parent dfb8bf6 commit ad52730

File tree

11 files changed

+72
-72
lines changed

11 files changed

+72
-72
lines changed

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryLongTermSystemPromptIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.ai.chat.chatbot.DefaultChatBot;
3030
import org.springframework.ai.chat.chatbot.DefaultStreamingChatBot;
3131
import org.springframework.ai.chat.chatbot.StreamingChatBot;
32-
import org.springframework.ai.chat.history.VectorStoreChatMemoryAgentListener;
32+
import org.springframework.ai.chat.history.VectorStoreChatMemoryChatBotListener;
3333
import org.springframework.ai.chat.history.VectorStoreChatMemoryRetriever;
3434
import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer;
3535
import org.springframework.ai.chat.history.SystemPromptChatMemoryAugmentor;
@@ -98,26 +98,26 @@ public TokenCountEstimator tokenCountEstimator() {
9898
}
9999

100100
@Bean
101-
public ChatBot memoryChatAgent(OpenAiChatClient chatClient, VectorStore vectorStore,
101+
public ChatBot memoryChatBot(OpenAiChatClient chatClient, VectorStore vectorStore,
102102
TokenCountEstimator tokenCountEstimator) {
103103

104104
return DefaultChatBot.builder(chatClient)
105105
.withRetrievers(List.of(new VectorStoreChatMemoryRetriever(vectorStore, 10)))
106106
.withContentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000)))
107107
.withAugmentors(List.of(new SystemPromptChatMemoryAugmentor()))
108-
.withChatAgentListeners(List.of(new VectorStoreChatMemoryAgentListener(vectorStore)))
108+
.withChatBotListeners(List.of(new VectorStoreChatMemoryChatBotListener(vectorStore)))
109109
.build();
110110
}
111111

112112
@Bean
113-
public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient streamingChatClient, VectorStore vectorStore,
113+
public StreamingChatBot memoryStreamingChatBot(OpenAiChatClient streamingChatClient, VectorStore vectorStore,
114114
TokenCountEstimator tokenCountEstimator) {
115115

116116
return DefaultStreamingChatBot.builder(streamingChatClient)
117117
.withRetrievers(List.of(new VectorStoreChatMemoryRetriever(vectorStore, 10)))
118118
.withDocumentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000)))
119119
.withAugmentors(List.of(new SystemPromptChatMemoryAugmentor()))
120-
.withChatAgentListeners(List.of(new VectorStoreChatMemoryAgentListener(vectorStore)))
120+
.withChatBotListeners(List.of(new VectorStoreChatMemoryChatBotListener(vectorStore)))
121121
.build();
122122
}
123123

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermMessageListIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.springframework.ai.chat.chatbot.DefaultStreamingChatBot;
2525
import org.springframework.ai.chat.chatbot.StreamingChatBot;
2626
import org.springframework.ai.chat.history.ChatMemory;
27-
import org.springframework.ai.chat.history.ChatMemoryAgentListener;
27+
import org.springframework.ai.chat.history.ChatMemoryChatBotListener;
2828
import org.springframework.ai.chat.history.ChatMemoryRetriever;
2929
import org.springframework.ai.chat.history.InMemoryChatMemory;
3030
import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer;
@@ -74,26 +74,26 @@ public TokenCountEstimator tokenCountEstimator() {
7474
}
7575

7676
@Bean
77-
public ChatBot memoryChatAgent(OpenAiChatClient chatClient, ChatMemory chatHistory,
77+
public ChatBot memoryChatBot(OpenAiChatClient chatClient, ChatMemory chatHistory,
7878
TokenCountEstimator tokenCountEstimator) {
7979

8080
return DefaultChatBot.builder(chatClient)
8181
.withRetrievers(List.of(new ChatMemoryRetriever(chatHistory)))
8282
.withContentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000)))
8383
.withAugmentors(List.of(new MessageChatMemoryAugmentor()))
84-
.withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory)))
84+
.withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory)))
8585
.build();
8686
}
8787

8888
@Bean
89-
public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient streamingChatClient, ChatMemory chatHistory,
89+
public StreamingChatBot memoryStreamingChatBot(OpenAiChatClient streamingChatClient, ChatMemory chatHistory,
9090
TokenCountEstimator tokenCountEstimator) {
9191

9292
return DefaultStreamingChatBot.builder(streamingChatClient)
9393
.withRetrievers(List.of(new ChatMemoryRetriever(chatHistory)))
9494
.withDocumentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000)))
9595
.withAugmentors(List.of(new MessageChatMemoryAugmentor()))
96-
.withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory)))
96+
.withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory)))
9797
.build();
9898
}
9999

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermSystemPromptIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.springframework.ai.chat.chatbot.DefaultStreamingChatBot;
2626
import org.springframework.ai.chat.chatbot.StreamingChatBot;
2727
import org.springframework.ai.chat.history.ChatMemory;
28-
import org.springframework.ai.chat.history.ChatMemoryAgentListener;
28+
import org.springframework.ai.chat.history.ChatMemoryChatBotListener;
2929
import org.springframework.ai.chat.history.ChatMemoryRetriever;
3030
import org.springframework.ai.chat.history.InMemoryChatMemory;
3131
import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer;
@@ -75,26 +75,26 @@ public TokenCountEstimator tokenCountEstimator() {
7575
}
7676

7777
@Bean
78-
public ChatBot memoryChatAgent(OpenAiChatClient chatClient, ChatMemory chatHistory,
78+
public ChatBot memoryChatBot(OpenAiChatClient chatClient, ChatMemory chatHistory,
7979
TokenCountEstimator tokenCountEstimator) {
8080

8181
return DefaultChatBot.builder(chatClient)
8282
.withRetrievers(List.of(new ChatMemoryRetriever(chatHistory)))
8383
.withContentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000)))
8484
.withAugmentors(List.of(new SystemPromptChatMemoryAugmentor()))
85-
.withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory)))
85+
.withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory)))
8686
.build();
8787
}
8888

8989
@Bean
90-
public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient streamingChatClient, ChatMemory chatHistory,
90+
public StreamingChatBot memoryStreamingChatBot(OpenAiChatClient streamingChatClient, ChatMemory chatHistory,
9191
TokenCountEstimator tokenCountEstimator) {
9292

9393
return DefaultStreamingChatBot.builder(streamingChatClient)
9494
.withRetrievers(List.of(new ChatMemoryRetriever(chatHistory)))
9595
.withDocumentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000)))
9696
.withAugmentors(List.of(new SystemPromptChatMemoryAugmentor()))
97-
.withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory)))
97+
.withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory)))
9898
.build();
9999
}
100100

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/LongShortTermChatMemoryWithRagIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434

3535
import org.springframework.ai.chat.chatbot.DefaultChatBot;
3636
import org.springframework.ai.chat.history.ChatMemory;
37-
import org.springframework.ai.chat.history.ChatMemoryAgentListener;
37+
import org.springframework.ai.chat.history.ChatMemoryChatBotListener;
3838
import org.springframework.ai.chat.history.ChatMemoryRetriever;
3939
import org.springframework.ai.chat.history.InMemoryChatMemory;
4040
import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer;
4141
import org.springframework.ai.chat.history.SystemPromptChatMemoryAugmentor;
42-
import org.springframework.ai.chat.history.VectorStoreChatMemoryAgentListener;
42+
import org.springframework.ai.chat.history.VectorStoreChatMemoryChatBotListener;
4343
import org.springframework.ai.chat.history.VectorStoreChatMemoryRetriever;
4444
import org.springframework.ai.chat.messages.UserMessage;
4545
import org.springframework.ai.chat.prompt.Prompt;
@@ -187,7 +187,7 @@ public TokenCountEstimator tokenCountEstimator() {
187187
}
188188

189189
@Bean
190-
public ChatBot memoryChatAgent(OpenAiChatClient chatClient, VectorStore vectorStore,
190+
public ChatBot memoryChatBot(OpenAiChatClient chatClient, VectorStore vectorStore,
191191
TokenCountEstimator tokenCountEstimator, ChatMemory chatHistory) {
192192

193193
return DefaultChatBot.builder(chatClient)
@@ -214,8 +214,8 @@ public ChatBot memoryChatAgent(OpenAiChatClient chatClient, VectorStore vectorSt
214214
Set.of(TransformerContentType.LONG_TERM_MEMORY)),
215215
new SystemPromptChatMemoryAugmentor(Set.of(TransformerContentType.SHORT_TERM_MEMORY))))
216216

217-
.withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory),
218-
new VectorStoreChatMemoryAgentListener(vectorStore,
217+
.withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory),
218+
new VectorStoreChatMemoryChatBotListener(vectorStore,
219219
Map.of(TransformerContentType.LONG_TERM_MEMORY, ""))))
220220
.build();
221221
}

spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatAgentListener.java renamed to spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatBotListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import org.springframework.ai.chat.prompt.transformer.PromptContext;
2020

2121
/**
22-
* The ChatAgentListener is a callback interface that can be implemented by classes that
22+
* The ChatBotListener is a callback interface that can be implemented by classes that
2323
* want to be notified of the completion of a ChatBot execution.
2424
*
2525
* @author Mark Pollack
2626
* @author Christian Tzolov
2727
*/
28-
public interface ChatAgentListener {
28+
public interface ChatBotListener {
2929

3030
default void onStart(PromptContext promptContext) {
3131

spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultChatBot.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ public class DefaultChatBot implements ChatBot {
3838

3939
private List<PromptTransformer> augmentors;
4040

41-
private List<ChatAgentListener> chatAgentListeners;
41+
private List<ChatBotListener> chatBotListeners;
4242

4343
public DefaultChatBot(ChatClient chatClient, List<PromptTransformer> retrievers,
4444
List<PromptTransformer> documentPostProcessors, List<PromptTransformer> augmentors,
45-
List<ChatAgentListener> chatAgentListeners) {
45+
List<ChatBotListener> chatBotListeners) {
4646
Objects.requireNonNull(chatClient, "chatClient must not be null");
4747
this.chatClient = chatClient;
4848
this.retrievers = retrievers;
4949
this.documentPostProcessors = documentPostProcessors;
5050
this.augmentors = augmentors;
51-
this.chatAgentListeners = chatAgentListeners;
51+
this.chatBotListeners = chatBotListeners;
5252
}
5353

54-
public static DefaultChatAgentBuilder builder(ChatClient chatClient) {
55-
return new DefaultChatAgentBuilder().withChatClient(chatClient);
54+
public static DefaultChatBotBuilder builder(ChatClient chatClient) {
55+
return new DefaultChatBotBuilder().withChatClient(chatClient);
5656
}
5757

5858
@Override
@@ -76,7 +76,7 @@ public ChatBotResponse call(PromptContext promptContext) {
7676
}
7777

7878
// Invoke Listeners onStart
79-
for (ChatAgentListener listener : this.chatAgentListeners) {
79+
for (ChatBotListener listener : this.chatBotListeners) {
8080
listener.onStart(promptContextOnStart);
8181
}
8282

@@ -85,13 +85,13 @@ public ChatBotResponse call(PromptContext promptContext) {
8585

8686
// Invoke Listeners onComplete
8787
ChatBotResponse chatBotResponse = new ChatBotResponse(promptContext, chatResponse);
88-
for (ChatAgentListener listener : this.chatAgentListeners) {
88+
for (ChatBotListener listener : this.chatBotListeners) {
8989
listener.onComplete(chatBotResponse);
9090
}
9191
return chatBotResponse;
9292
}
9393

94-
public static class DefaultChatAgentBuilder {
94+
public static class DefaultChatBotBuilder {
9595

9696
private ChatClient chatClient;
9797

@@ -101,35 +101,35 @@ public static class DefaultChatAgentBuilder {
101101

102102
private List<PromptTransformer> augmentors = new ArrayList<>();
103103

104-
private List<ChatAgentListener> chatAgentListeners = new ArrayList<>();
104+
private List<ChatBotListener> chatBotListeners = new ArrayList<>();
105105

106-
public DefaultChatAgentBuilder withChatClient(ChatClient chatClient) {
106+
public DefaultChatBotBuilder withChatClient(ChatClient chatClient) {
107107
this.chatClient = chatClient;
108108
return this;
109109
}
110110

111-
public DefaultChatAgentBuilder withRetrievers(List<PromptTransformer> retrievers) {
111+
public DefaultChatBotBuilder withRetrievers(List<PromptTransformer> retrievers) {
112112
this.retrievers = retrievers;
113113
return this;
114114
}
115115

116-
public DefaultChatAgentBuilder withContentPostProcessors(List<PromptTransformer> documentPostProcessors) {
116+
public DefaultChatBotBuilder withContentPostProcessors(List<PromptTransformer> documentPostProcessors) {
117117
this.documentPostProcessors = documentPostProcessors;
118118
return this;
119119
}
120120

121-
public DefaultChatAgentBuilder withAugmentors(List<PromptTransformer> augmentors) {
121+
public DefaultChatBotBuilder withAugmentors(List<PromptTransformer> augmentors) {
122122
this.augmentors = augmentors;
123123
return this;
124124
}
125125

126-
public DefaultChatAgentBuilder withChatAgentListeners(List<ChatAgentListener> chatAgentListeners) {
127-
this.chatAgentListeners = chatAgentListeners;
126+
public DefaultChatBotBuilder withChatBotListeners(List<ChatBotListener> chatBotListeners) {
127+
this.chatBotListeners = chatBotListeners;
128128
return this;
129129
}
130130

131131
public DefaultChatBot build() {
132-
return new DefaultChatBot(chatClient, retrievers, documentPostProcessors, augmentors, chatAgentListeners);
132+
return new DefaultChatBot(chatClient, retrievers, documentPostProcessors, augmentors, chatBotListeners);
133133
}
134134

135135
}

spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultStreamingChatBot.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ public class DefaultStreamingChatBot implements StreamingChatBot {
4141

4242
private List<PromptTransformer> augmentors;
4343

44-
private List<ChatAgentListener> chatAgentListeners;
44+
private List<ChatBotListener> chatBotListeners;
4545

4646
public DefaultStreamingChatBot(StreamingChatClient chatClient, List<PromptTransformer> retrievers,
4747
List<PromptTransformer> documentPostProcessors, List<PromptTransformer> augmentors,
48-
List<ChatAgentListener> chatAgentListeners) {
48+
List<ChatBotListener> chatBotListeners) {
4949
Objects.requireNonNull(chatClient, "chatClient must not be null");
5050
this.streamingChatClient = chatClient;
5151
this.retrievers = retrievers;
5252
this.documentPostProcessors = documentPostProcessors;
5353
this.augmentors = augmentors;
54-
this.chatAgentListeners = chatAgentListeners;
54+
this.chatBotListeners = chatBotListeners;
5555
}
5656

57-
public static DefaultChatAgentBuilder builder(StreamingChatClient chatClient) {
58-
return new DefaultChatAgentBuilder().withChatClient(chatClient);
57+
public static DefaultChatBotBuilder builder(StreamingChatClient chatClient) {
58+
return new DefaultChatBotBuilder().withChatClient(chatClient);
5959
}
6060

6161
@Override
@@ -79,7 +79,7 @@ public StreamingChatBotResponse stream(PromptContext promptContext) {
7979
}
8080

8181
// Invoke Listeners onStart
82-
for (ChatAgentListener listener : this.chatAgentListeners) {
82+
for (ChatBotListener listener : this.chatBotListeners) {
8383
listener.onStart(promptContextOnStart);
8484
}
8585

@@ -88,7 +88,7 @@ public StreamingChatBotResponse stream(PromptContext promptContext) {
8888

8989
Flux<ChatResponse> fluxChatResponse = new MessageAggregator()
9090
.aggregate(this.streamingChatClient.stream(promptContext.getPrompt()), chatResponse -> {
91-
for (ChatAgentListener listener : this.chatAgentListeners) {
91+
for (ChatBotListener listener : this.chatBotListeners) {
9292
listener.onComplete(new ChatBotResponse(promptContext2, chatResponse));
9393
}
9494
});
@@ -97,7 +97,7 @@ public StreamingChatBotResponse stream(PromptContext promptContext) {
9797
return new StreamingChatBotResponse(promptContext, fluxChatResponse);
9898
}
9999

100-
public static class DefaultChatAgentBuilder {
100+
public static class DefaultChatBotBuilder {
101101

102102
private StreamingChatClient chatClient;
103103

@@ -107,36 +107,36 @@ public static class DefaultChatAgentBuilder {
107107

108108
private List<PromptTransformer> augmentors = new ArrayList<>();
109109

110-
private List<ChatAgentListener> chatAgentListeners = new ArrayList<>();
110+
private List<ChatBotListener> chatBotListeners = new ArrayList<>();
111111

112-
public DefaultChatAgentBuilder withChatClient(StreamingChatClient chatClient) {
112+
public DefaultChatBotBuilder withChatClient(StreamingChatClient chatClient) {
113113
this.chatClient = chatClient;
114114
return this;
115115
}
116116

117-
public DefaultChatAgentBuilder withRetrievers(List<PromptTransformer> retrievers) {
117+
public DefaultChatBotBuilder withRetrievers(List<PromptTransformer> retrievers) {
118118
this.retrievers = retrievers;
119119
return this;
120120
}
121121

122-
public DefaultChatAgentBuilder withDocumentPostProcessors(List<PromptTransformer> documentPostProcessors) {
122+
public DefaultChatBotBuilder withDocumentPostProcessors(List<PromptTransformer> documentPostProcessors) {
123123
this.documentPostProcessors = documentPostProcessors;
124124
return this;
125125
}
126126

127-
public DefaultChatAgentBuilder withAugmentors(List<PromptTransformer> augmentors) {
127+
public DefaultChatBotBuilder withAugmentors(List<PromptTransformer> augmentors) {
128128
this.augmentors = augmentors;
129129
return this;
130130
}
131131

132-
public DefaultChatAgentBuilder withChatAgentListeners(List<ChatAgentListener> chatAgentListeners) {
133-
this.chatAgentListeners = chatAgentListeners;
132+
public DefaultChatBotBuilder withChatBotListeners(List<ChatBotListener> chatBotListeners) {
133+
this.chatBotListeners = chatBotListeners;
134134
return this;
135135
}
136136

137137
public DefaultStreamingChatBot build() {
138138
return new DefaultStreamingChatBot(chatClient, retrievers, documentPostProcessors, augmentors,
139-
chatAgentListeners);
139+
chatBotListeners);
140140
}
141141

142142
}

spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryAgentListener.java renamed to spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryChatBotListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.List;
2020

2121
import org.springframework.ai.chat.chatbot.ChatBotResponse;
22-
import org.springframework.ai.chat.chatbot.ChatAgentListener;
22+
import org.springframework.ai.chat.chatbot.ChatBotListener;
2323
import org.springframework.ai.chat.messages.Message;
2424
import org.springframework.ai.chat.messages.MessageType;
2525
import org.springframework.ai.chat.prompt.transformer.PromptContext;
@@ -28,11 +28,11 @@
2828
/**
2929
* @author Christian Tzolov
3030
*/
31-
public class ChatMemoryAgentListener implements ChatAgentListener {
31+
public class ChatMemoryChatBotListener implements ChatBotListener {
3232

3333
private final ChatMemory chatHistory;
3434

35-
public ChatMemoryAgentListener(ChatMemory chatHistory) {
35+
public ChatMemoryChatBotListener(ChatMemory chatHistory) {
3636
this.chatHistory = chatHistory;
3737
}
3838

0 commit comments

Comments
 (0)