Easy-agent介绍

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-agent1.引入依赖在你的 Spring Boot 项目中添加 Easy-Agent Starterdependency groupIdio.github.songrongzhen/groupId artifactIdeasy-agent-spring-boot-starter/artifactId version0.1.6/version /dependency2.基础配置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.定义工具EasyTool3.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) { ListChatMessage messages List.of( ChatMessage.system(你是一个AI领域专家), ChatMessage.user(message) ); return llmService.chat(messages); } }4.2 流式对话GetMapping(/chat/stream) public ResponseEntityStreamingResponseBody chatStream(RequestParam String message) { StreamingResponseBody stream outputStream - { Writer writer new OutputStreamWriter(outputStream); ListChatMessage 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;charsetUTF-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.pdf5.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. 构建带上下文的对话 ListChatMessage 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 Codeadd 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 Code2. 在 Claude Code 中说我想创建一个 skill3. 系统引导你输入- Skill 名称- Skill 描述- 使用边界- 可调用的工具- 使用示例4. 生成 SKILL.md 文件到 skill/ 目录创建属于自己的技能 Java 零侵入让系统秒变 AI 应用还在为系统智能化改造发愁吗Easy-Agent 来了目前在GitHub 获得160 Stars不用重构代码不用更换架构只需引入一个 Starter就能让你的 Spring Boot 应用瞬间拥有大模型、工具调用和知识库问答的超能力 传送门https://github.com/songrongzhen/easy-agent开源不易走过路过别忘了留下一颗 ⭐️ Star 哦感谢大家的支持