Skip to content

Commit 4abf3e7

Browse files
authored
fix(agent): set interceptors in NacosReactAgentBuilder correctly (#4175)
1 parent c628da3 commit 4abf3e7

File tree

3 files changed

+628
-15
lines changed

3 files changed

+628
-15
lines changed

spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/DefaultBuilder.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,8 @@ public ReactAgent build() {
105105
if (StringUtils.hasLength(outputSchema)) {
106106
llmNodeBuilder.outputSchema(outputSchema);
107107
}
108-
109-
// Separate unified interceptors by type
110-
if (CollectionUtils.isNotEmpty(interceptors)) {
111-
modelInterceptors = new ArrayList<>();
112-
toolInterceptors = new ArrayList<>();
113-
114-
for (Interceptor interceptor : interceptors) {
115-
if (interceptor instanceof ModelInterceptor) {
116-
modelInterceptors.add((ModelInterceptor) interceptor);
117-
}
118-
if (interceptor instanceof ToolInterceptor) {
119-
toolInterceptors.add((ToolInterceptor) interceptor);
120-
}
121-
}
122-
}
108+
109+
separateInterceptorsByType();
123110

124111
List<ToolCallback> allTools = gatherLocalTools();
125112

@@ -170,6 +157,25 @@ public ReactAgent build() {
170157
return new ReactAgent(llmNode, toolNode, buildConfig(), this);
171158
}
172159

160+
/**
161+
* Separate unified interceptors by type into modelInterceptors and toolInterceptors.
162+
*/
163+
protected void separateInterceptorsByType() {
164+
if (CollectionUtils.isNotEmpty(interceptors)) {
165+
modelInterceptors = new ArrayList<>();
166+
toolInterceptors = new ArrayList<>();
167+
168+
for (Interceptor interceptor : interceptors) {
169+
if (interceptor instanceof ModelInterceptor) {
170+
modelInterceptors.add((ModelInterceptor) interceptor);
171+
}
172+
if (interceptor instanceof ToolInterceptor) {
173+
toolInterceptors.add((ToolInterceptor) interceptor);
174+
}
175+
}
176+
}
177+
}
178+
173179
/**
174180
* Collect all tools from various sources.
175181
* <p>

spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/NacosReactAgentBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public ReactAgent build() {
105105
McpServersVO mcpServersVO = NacosMcpToolsInjector.getMcpServersVO(nacosOptions);
106106
agentVOHolder.setMcpServersVO(mcpServersVO);
107107

108+
separateInterceptorsByType();
109+
108110
List<ToolCallback> allTools = new ArrayList<>();
109111
this.localTools = gatherLocalTools();
110112
List<ToolCallback> mcpTools = convert(nacosOptions, mcpServersVO);

0 commit comments

Comments
 (0)