## 主要改动
1. Prompt 配置化
- 从硬编码改为独立 Markdown 文件管理
- 新增 AiOpsPromptProperties 配置类,使用 @PostConstruct 加载
- 创建 prompts/{planner,executor,supervisor}-prompt.md
2. 集成 LookupKnowledgeTool
- 在 AiOpsService 中注入 LookupKnowledgeTool
- 添加到工具数组,只给 Executor Agent 使用
- 符合 3-Agent 协同分析模式
3. Executor Prompt 增强
- 添加工具选择指南(精确关键词 vs 模糊概念)
- 明确降级策略(lookup_knowledge 未找到时降级到 queryInternalDocs)
## 优势
- 易于维护:Prompt 修改不需重新编译
- 格式友好:Markdown 原生支持代码块和表格
- 性能优化:精确关键词查询 < 10ms(L0 匹配)
## 文件变更
- 新增:AiOpsPromptProperties.java
- 新增:prompts/planner-prompt.md
- 新增:prompts/executor-prompt.md
- 新增:prompts/supervisor-prompt.md
- 修改:AiOpsService.java(-136 行硬编码,+5 行配置引用)
57 lines
1.7 KiB
Java
57 lines
1.7 KiB
Java
package com.superbiz.agent.config;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
import java.io.IOException;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
/**
|
|
* AI Ops Agent Prompt 配置
|
|
* 从独立的 Markdown 文件加载 Prompt 模板
|
|
*/
|
|
@Slf4j
|
|
@Configuration
|
|
public class AiOpsPromptProperties {
|
|
|
|
private String planner;
|
|
private String executor;
|
|
private String supervisor;
|
|
|
|
@PostConstruct
|
|
public void loadPrompts() {
|
|
try {
|
|
planner = loadPromptFromFile("prompts/planner-prompt.md");
|
|
executor = loadPromptFromFile("prompts/executor-prompt.md");
|
|
supervisor = loadPromptFromFile("prompts/supervisor-prompt.md");
|
|
|
|
log.info("AI Ops Prompts 加载成功");
|
|
log.debug("Planner Prompt 长度: {} 字符", planner.length());
|
|
log.debug("Executor Prompt 长度: {} 字符", executor.length());
|
|
log.debug("Supervisor Prompt 长度: {} 字符", supervisor.length());
|
|
} catch (IOException e) {
|
|
log.error("加载 Prompt 文件失败", e);
|
|
throw new RuntimeException("Failed to load AI Ops prompts", e);
|
|
}
|
|
}
|
|
|
|
private String loadPromptFromFile(String path) throws IOException {
|
|
ClassPathResource resource = new ClassPathResource(path);
|
|
return new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
|
}
|
|
|
|
public String getPlanner() {
|
|
return planner;
|
|
}
|
|
|
|
public String getExecutor() {
|
|
return executor;
|
|
}
|
|
|
|
public String getSupervisor() {
|
|
return supervisor;
|
|
}
|
|
}
|