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 对话能力)
java 复制代码
easy-agent:
  llm:
    enabled: true
    model: qwen-plus              # 自动识别为通义千问
    api-key: ${DASHSCOPE_API_KEY}
2.2 完整配置(全功能)
java 复制代码
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: ./skill

3.定义工具(@EasyTool)

3.1 创建工具类
java 复制代码
@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 基本对话
java 复制代码
@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 流式对话
java 复制代码
@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 增强
java 复制代码
@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
java 复制代码
add claude mcp http://{your-project-address}/mcp
6.3 使用 Claude Code 调用工具

启动 Claude Code 后,直接对话即可:

java 复制代码
用户:帮我计算 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 描述

  • 使用边界

  • 可调用的工具

  • 使用示例

  1. 生成 SKILL.md 文件到 skill/ 目录

💡 Java 零侵入让系统秒变 AI 应用!

还在为系统智能化改造发愁吗?Easy-Agent 来了!

不用重构代码,不用更换架构,只需引入一个 Starter,就能让你的 Spring Boot 应用瞬间拥有大模型、工具调用和知识库问答的超能力!

🔗 传送门:https://github.com/songrongzhen/easy-agent

开源不易,走过路过别忘了留下一颗 ⭐️ Star 哦!感谢大家的支持!

以上是JDK17+版本,作者目前还没有将JDK8版本开源

相关推荐
xingyuzhisuan1 小时前
Redis 多级缓存落地聚合 API:重复请求降本 70% 实战数据
数据库·redis·缓存·ai
一锅炖出任易仙1 小时前
创梦汤锅学习日记day31
学习·ai
DS随心转APP1 小时前
怎么让智谱清言生成 excel?借助 AI 导出鸭横向测评导出方法,一站式破解表格生成困扰
人工智能·ai·excel·deepseek·ai导出鸭
羑悻的小杀马特1 小时前
拆解下一代LLMOps:从“能用”到“好用”,中间只隔了一个智能路由!
人工智能·docker·自动化·agent
阿里云大数据AI技术2 小时前
阿里云 EMR Serverless StarRocks Skills 正式发布
starrocks·阿里云·serverless·agent·skill
Shawn_Shawn2 小时前
Apache Doris Ai Function学习
后端·llm
Ajie'Blog2 小时前
2026年AI安全与治理:从幻觉到系统性欺骗的攻防之战
javascript·人工智能·安全·rpc·json·rag
DigitalOcean3 小时前
微调后的 LLM 如何部署到生产环境?从GPU 推理端点的搭建、测试与上线全流程
llm·gpu