Easy-agent介绍
介绍
目前,我的工作主要聚焦于 Agent 和 SKILL 相关领域。随着公司多个项目完成 Agent 化升级,我将项目集成 Agent 架构的经验进行总结和封装,最终开发出一个可复用组件——Easy-agent。
Easy-agent 是一款轻量级 Spring Boot AI 开发套件,通过简单的@EasyTool注解即可将业务方法快速转换为 AI 可调用的工具接口。该组件支持 MCP 协议,使 Claude Code、Codex 等能够直接调用你的代码。
主要特性包括:
- 支持多 LLM 提供商(通义千问/DeepSeek/Ollama/OpenAI)
- 提供 RAG 知识库检索功能(支持 PDF/Excel 一键导入)
- 内置对话式 Skill 生成器,无需编写代码即可定义专属 AI 技能
Easy-agent 采用零侵入设计,仅需添加一个依赖和一行注解,就能为 Spring Boot 项目赋予完整的 AI 能力。它是企业内部 AI 助手、知识库问答系统以及 AI 驱动工具集的理想选择。
Easy-agent的核心优势包括
1. 零门槛接入:只需要引入依赖 + 一个注解,无需复杂配置,开发者零学习成本即可让代码拥有 AI 能力。
2. 无侵入设计:对现有业务代码零侵入,只需要在方法上添加 @EasyTool 注解,无需重构现有架构。
3.一站式方案:从工具注册 → LLM 集成 → RAG 知识库 → Skill 生成,完整覆盖 AI 开发全链路
4. MCP 协议原生支持:内置 MCP 协议,Claude Code 等 AI 助手可直接调用你的业务代码,无需额外适配。
5.多 LLM 提供商支持:通义千问/DeepSeek/Ollama/OpenAI 开箱即用,轻松切换,无需关心底层实现。
如何开始使用Easy-agent:
1.引入依赖
在你的 Spring Boot 项目中添加 Easy-Agent Starter:
<dependency> <groupId>io.github.songrongzhen</groupId> <artifactId>easy-agent-spring-boot-starter</artifactId> <version>0.1.6</version> </dependency>2.基础配置
2.1 最简配置(LLM 对话能力)
easy-agent: llm: enabled: true model: qwen-plus # 自动识别为通义千问 api-key: ${DASHSCOPE_API_KEY}2.2 完整配置(全功能)
easy-agent: # MCP 配置 mcp: enabled: true # LLM 配置 llm: enabled: true model: qwen-plus api-key: ${DASHSCOPE_API_KEY} # RAG 配置 rag: enabled: true storage-type: IN_MEMORY search: strategy: AUTO cosine: enabled: true tfidf: enabled: true pdf: enabled: true resource-path: classpath:knowledge/ excel: enabled: true resource-path: classpath:knowledge/ # Skill 配置(默认开启) skill: skill-output-path: ./skill3.定义工具(@EasyTool)
3.1 创建工具类
@Service public class MyTools { @EasyTool(name = "getCurrentTime", description = "获取当前时间") public String getCurrentTime() { return LocalDateTime.now().toString(); } @EasyTool(name = "calculate", description = "计算两个数字的和") public int add( @ToolParam(name = "a", description = "第一个数字") int a, @ToolParam(name = "b", description = "第二个数字") int b) { return a + b; } @EasyTool(name = "queryUser", description = "查询用户信息") public UserInfo queryUser( @ToolParam(name = "userId", description = "用户ID") String userId) { // 调用业务逻辑查询用户 return userService.findById(userId); } }3.2 工具自动注册
Easy-Agent 会自动扫描所有 @EasyTool 注解的方法并注册到 ToolRegistry ,无需手动配置
4.LLM 对话能力
4.1 基本对话
@RestController public class ChatController { @Autowired private LlmService llmService; @GetMapping("/chat") public ChatResponse chat(@RequestParam String message) { List<ChatMessage> messages = List.of( ChatMessage.system("你是一个AI领域专家"), ChatMessage.user(message) ); return llmService.chat(messages); } }4.2 流式对话
@GetMapping("/chat/stream") public ResponseEntity<StreamingResponseBody> chatStream(@RequestParam String message) { StreamingResponseBody stream = outputStream -> { Writer writer = new OutputStreamWriter(outputStream); List<ChatMessage> messages = List.of(ChatMessage.user(message)); llmService.chatStream(messages, token -> { if (token != null) { writer.write(token); writer.flush(); } else { writer.write("\n[DONE]"); writer.flush(); } }); }; return ResponseEntity.ok() .contentType(MediaType.parseMediaType("text/event-stream;charset=UTF-8")) .header("Cache-Control", "no-cache") .body(stream); }5.RAG 知识库
5.1 准备知识库文件
将 PDF 或 Excel 文件放到 src/main/resources/knowledge/ 目录:
src/main/resources/knowledge/
├── product-manual.pdf
├── faq.xlsx
└── user-guide.pdf
5.2 使用 RAG 增强
@RestController public class RagController { @Autowired private RagService ragService; @Autowired private LlmService llmService; @GetMapping("/rag/chat") public ChatResponse ragChat(@RequestParam String question) { // 1. 从知识库检索相关内容 String context = ragService.searchAndConcat(question, 5); // 2. 构建带上下文的对话 List<ChatMessage> messages = List.of( ChatMessage.system("基于以下知识回答问题,如果知识中没有相关信息,请诚实说明:\n" + context), ChatMessage.user(question) ); // 3. 调用 LLM return llmService.chat(messages); } }6.MCP 协议(Claude Code 连接)
6.1 启动你的服务
6.2 连接 Claude Code
add claude mcp http://{your-project-address}/mcp6.3 使用 Claude Code 调用工具
启动 Claude Code 后,直接对话即可:
用户:帮我计算 3 + 5 Claude:调用 add(3, 5) → 8 用户:查询用户 ID 为 123 的信息 Claude:调用 queryUser("123") → 返回用户信息7.Skill 生成
7.1 生成流程
1. 启动服务并连接 Claude Code
2. 在 Claude Code 中说:"我想创建一个 skill"
3. 系统引导你输入:
- Skill 名称
- Skill 描述
- 使用边界
- 可调用的工具
- 使用示例
4. 生成 SKILL.md 文件到 skill/ 目录
创建属于自己的技能
💡 Java 零侵入让系统秒变 AI 应用!
还在为系统智能化改造发愁吗?Easy-Agent 来了!目前在GitHub 获得160+ Stars
不用重构代码,不用更换架构,只需引入一个 Starter,就能让你的 Spring Boot 应用瞬间拥有大模型、工具调用和知识库问答的超能力!
🔗 传送门:https://github.com/songrongzhen/easy-agent
开源不易,走过路过别忘了留下一颗 ⭐️ Star 哦!感谢大家的支持!
