Skip to content

Commit 17eaaa6

Browse files
committed
feat(agent): 新增智能体管理及相关功能支持(需执行upgrades/v1.1.0相关SQL)
1 parent 2c178b4 commit 17eaaa6

51 files changed

Lines changed: 4919 additions & 1058 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bootstrap/src/main/java/com/nageoffer/ai/ragent/audit/constant/BizChangeBizType.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
package com.nageoffer.ai.ragent.audit.constant;
1919

20+
import lombok.AccessLevel;
21+
import lombok.NoArgsConstructor;
22+
23+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2024
public final class BizChangeBizType {
2125

2226
public static final String KNOWLEDGE_BASE = "KNOWLEDGE_BASE";
@@ -28,7 +32,5 @@ public final class BizChangeBizType {
2832
public static final String QUERY_TERM_MAPPING = "QUERY_TERM_MAPPING";
2933
public static final String SAMPLE_QUESTION = "SAMPLE_QUESTION";
3034
public static final String USER = "USER";
31-
32-
private BizChangeBizType() {
33-
}
35+
public static final String AGENT_PROFILE = "AGENT_PROFILE";
3436
}

bootstrap/src/main/java/com/nageoffer/ai/ragent/rag/config/DemoModeProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
@Data
2828
@Configuration
29-
@ConfigurationProperties(prefix = "app")
29+
@ConfigurationProperties(prefix = "ragent")
3030
public class DemoModeProperties {
3131

3232
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.nageoffer.ai.ragent.rag.config;
19+
20+
import cn.hutool.core.util.StrUtil;
21+
22+
/**
23+
* 执行架构档位,由 ragent.engine.type 指定
24+
* <p>
25+
* 属部署级决策(切换需重启,且 AGENT 依赖外部 ReAct 服务存活),因此不开放后台切换
26+
*/
27+
public enum OrchestrationMode {
28+
29+
/**
30+
* v1 编排管线:意图分类 → 检索 → 合成,链路确定、延迟低
31+
*/
32+
WORKFLOW,
33+
34+
/**
35+
* v2 ReAct 架构:主 Agent 决策,RAG 管线降级为其中一个 Tool
36+
*/
37+
AGENT;
38+
39+
/**
40+
* 解析配置值,大小写不敏感,无法识别时回落 WORKFLOW
41+
*/
42+
public static OrchestrationMode of(String value) {
43+
if (StrUtil.isBlank(value)) {
44+
return WORKFLOW;
45+
}
46+
for (OrchestrationMode mode : values()) {
47+
if (mode.name().equalsIgnoreCase(value.trim())) {
48+
return mode;
49+
}
50+
}
51+
return WORKFLOW;
52+
}
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.nageoffer.ai.ragent.rag.config;
19+
20+
import lombok.Data;
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
import org.springframework.context.annotation.Configuration;
23+
24+
/**
25+
* 执行架构配置
26+
* 不挂在 rag 下:AGENT 档里 RAG 管线只是主 Agent 的一个 Tool,档位在语义上包含 RAG 而非从属于它
27+
*/
28+
@Data
29+
@Configuration
30+
@ConfigurationProperties(prefix = "ragent.engine")
31+
public class OrchestrationProperties {
32+
33+
/**
34+
* 档位取值,可选 workflow(默认)/ agent,大小写不敏感
35+
*/
36+
private String type = "workflow";
37+
38+
public OrchestrationMode getMode() {
39+
return OrchestrationMode.of(type);
40+
}
41+
}

bootstrap/src/main/java/com/nageoffer/ai/ragent/rag/constant/RAGConstant.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,20 @@ public class RAGConstant {
7979
*/
8080
public static final String GUIDANCE_AMBIGUITY_CHECK_PROMPT_PATH = "prompt/guidance-ambiguity-check.st";
8181

82-
/**
83-
* 系统对话提示词模板路径
84-
* 定义企业知识助手「小码」的角色设定和对话规则,包括打招呼、自我介绍、问题分类处理等场景。模板通过 {@code {question}} 占位符接收用户问题。
85-
*/
86-
public static final String CHAT_SYSTEM_PROMPT_PATH = "prompt/answer-chat-system.st";
8782

8883
/**
8984
* 查询改写 + 多问句拆分提示词模板路径
9085
* 要求同时返回改写后的单条查询和子问题列表
9186
*/
9287
public static final String QUERY_REWRITE_AND_SPLIT_PROMPT_PATH = "prompt/user-question-rewrite.st";
9388

94-
/**
95-
* 对话记忆压缩提示词模板路径
96-
* 通过 {@code {summary_max_chars}} 控制摘要长度上限
97-
*/
98-
public static final String CONVERSATION_SUMMARY_PROMPT_PATH = "prompt/conversation-summary.st";
9989

10090
/**
10191
* 会话标题生成提示词模板路径
10292
* 通过 {@code {title_max_chars}} 与 {@code {question}} 控制标题长度与输入问题
10393
*/
10494
public static final String CONVERSATION_TITLE_PROMPT_PATH = "prompt/conversation-title.st";
10595

106-
/**
107-
* 默认 RAG 问答提示词模板路径
108-
* 用于指导大模型基于检索到的文档内容进行准确回答,包含严格的事实性约束和链接处理规则
109-
*/
110-
public static final String RAG_ENTERPRISE_PROMPT_PATH = "prompt/answer-chat-kb.st";
11196

11297
/**
11398
* 知识资料回答的行内引用规则
@@ -128,23 +113,8 @@ public class RAGConstant {
128113
*/
129114
public static final String MCP_PARAMETER_EXTRACT_USER_PROMPT_PATH = "prompt/mcp-parameter-extract-user.st";
130115

131-
/**
132-
* MCP-only 场景提示词模板路径
133-
* 仅动态数据片段时使用
134-
*/
135-
public static final String MCP_ONLY_PROMPT_PATH = "prompt/answer-chat-mcp.st";
136116

137-
/**
138-
* MCP + KB 混合场景提示词模板路径
139-
* 兼顾动态数据片段与知识库内容的综合回答
140-
*/
141-
public static final String MCP_KB_MIXED_PROMPT_PATH = "prompt/answer-chat-mcp-kb-mixed.st";
142117

143-
/**
144-
* 推荐追问问题生成提示词模板路径
145-
* 通过 {@code {question}}、{@code {answer}}、{@code {count}} 注入问答与生成数量
146-
*/
147-
public static final String RECOMMENDED_QUESTIONS_PROMPT_PATH = "prompt/recommended-questions.st";
148118

149119
// ==================== 上下文格式化模板(单文件多 section) ====================
150120

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.nageoffer.ai.ragent.rag.controller;
19+
20+
import com.nageoffer.ai.ragent.framework.convention.Result;
21+
import com.nageoffer.ai.ragent.framework.web.Results;
22+
import com.nageoffer.ai.ragent.rag.controller.request.AgentProfileSaveRequest;
23+
import com.nageoffer.ai.ragent.rag.controller.request.AgentPromptSaveRequest;
24+
import com.nageoffer.ai.ragent.rag.controller.vo.AgentProfileListVO;
25+
import com.nageoffer.ai.ragent.rag.controller.vo.AgentPromptConfigVO;
26+
import com.nageoffer.ai.ragent.rag.service.AgentProfileAdminService;
27+
import lombok.RequiredArgsConstructor;
28+
import org.springframework.web.bind.annotation.DeleteMapping;
29+
import org.springframework.web.bind.annotation.GetMapping;
30+
import org.springframework.web.bind.annotation.PathVariable;
31+
import org.springframework.web.bind.annotation.PostMapping;
32+
import org.springframework.web.bind.annotation.PutMapping;
33+
import org.springframework.web.bind.annotation.RequestBody;
34+
import org.springframework.web.bind.annotation.RestController;
35+
36+
/**
37+
* 智能体管理控制器
38+
*/
39+
@RestController
40+
@RequiredArgsConstructor
41+
public class AgentProfileController {
42+
43+
private final AgentProfileAdminService agentProfileAdminService;
44+
45+
/**
46+
* 查询智能体列表
47+
*/
48+
@GetMapping("/agents")
49+
public Result<AgentProfileListVO> list() {
50+
return Results.success(agentProfileAdminService.list());
51+
}
52+
53+
/**
54+
* 创建智能体
55+
*/
56+
@PostMapping("/agents")
57+
public Result<String> create(@RequestBody AgentProfileSaveRequest requestParam) {
58+
return Results.success(agentProfileAdminService.create(requestParam));
59+
}
60+
61+
/**
62+
* 更新智能体名称与描述
63+
*/
64+
@PutMapping("/agents/{id}")
65+
public Result<Void> update(@PathVariable String id, @RequestBody AgentProfileSaveRequest requestParam) {
66+
agentProfileAdminService.update(id, requestParam);
67+
return Results.success();
68+
}
69+
70+
/**
71+
* 删除智能体
72+
*/
73+
@DeleteMapping("/agents/{id}")
74+
public Result<Void> delete(@PathVariable String id) {
75+
agentProfileAdminService.delete(id);
76+
return Results.success();
77+
}
78+
79+
/**
80+
* 激活智能体,立即对全部会话生效
81+
*/
82+
@PostMapping("/agents/{id}/activate")
83+
public Result<Void> activate(@PathVariable String id) {
84+
agentProfileAdminService.activate(id);
85+
return Results.success();
86+
}
87+
88+
/**
89+
* 查询该智能体的槽位配置,含槽位元数据与当前架构下的生效判定
90+
*/
91+
@GetMapping("/agents/{id}/prompts")
92+
public Result<AgentPromptConfigVO> prompts(@PathVariable String id) {
93+
return Results.success(agentProfileAdminService.loadPrompts(id));
94+
}
95+
96+
/**
97+
* 保存单个槽位,内容留空即恢复回落内置智能体
98+
*/
99+
@PutMapping("/agents/{id}/prompts/{slotKey}")
100+
public Result<Void> savePrompt(@PathVariable String id,
101+
@PathVariable String slotKey,
102+
@RequestBody AgentPromptSaveRequest requestParam) {
103+
agentProfileAdminService.savePrompt(id, slotKey, requestParam);
104+
return Results.success();
105+
}
106+
107+
/**
108+
* 查询内置智能体的槽位内容,供「从默认复制」
109+
*/
110+
@GetMapping("/agents/prompt-slots/{slotKey}/default")
111+
public Result<String> defaultPrompt(@PathVariable String slotKey) {
112+
return Results.success(agentProfileAdminService.defaultPrompt(slotKey));
113+
}
114+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.nageoffer.ai.ragent.rag.controller.request;
19+
20+
import lombok.Data;
21+
22+
/**
23+
* 智能体新建与改名请求
24+
*/
25+
@Data
26+
public class AgentProfileSaveRequest {
27+
28+
private String name;
29+
30+
private String description;
31+
32+
/**
33+
* 头像预设标识,由前端从预设表中挑选
34+
*/
35+
private String avatar;
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.nageoffer.ai.ragent.rag.controller.request;
19+
20+
import lombok.Data;
21+
22+
/**
23+
* 单个槽位提示词保存请求,内容留空即恢复回落内置智能体
24+
*/
25+
@Data
26+
public class AgentPromptSaveRequest {
27+
28+
private String content;
29+
}

0 commit comments

Comments
 (0)