当前位置: 首页 > news >正文

(续)Spring AI Agent Utils 环境与配置 _ Spring Agent 工具库


Spring AI Agent Utils _ Spring Agent 工具库 , 用Java开发 Agent 的全套工具集

https://blog.csdn.net/D1237890/article/details/160636082

Spring AI Agent Utils是一个基于Java开发的AI智能体工具库,为Spring AI应用提供Claude Code风格的智能体功能。该库0.7.0版本包含文件系统操作、Shell命令执行、Web搜索、任务管理等核心工具,支持可扩展的子智能体系统和技能模块。开发者可通过Maven依赖快速集成,利用其丰富的API构建复杂的智能体工作流。

该工具要求Java 17+和Spring Boot 3.x/4.x环境,与Spring AI 2.0.0兼容,适用于开发具有高级交互能力的AI应用。

<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.springaicommunity</groupId> <artifactId>spring-ai-agent-utils</artifactId> <version>0.7.0</version> <name>spring-ai-agent-utils</name> <description>Spring AI Agent Utilities</description> <url>https://github.com/spring-ai-community/spring-ai-agent-utils</url> <organization> <name>Spring AI Community</name> <url>https://github.com/spring-ai-community</url> </organization> <licenses> <license> <name>Apache License 2.0</name> <url>https://www.apache.org/licenses/LICENSE-2.0</url> </license> </licenses> <developers> <developer> <name>Christian Tzolov</name> </developer> </developers> <scm> <connection>git://github.com/spring-ai-community/spring-ai-agent-utils.git</connection> <developerConnection>git@github.com:spring-ai-community/spring-ai-agent-utils.git</developerConnection> <url>https://github.com/spring-ai-community/spring-ai-agent-utils</url> </scm> <dependencies> <dependency> <groupId>org.springaicommunity</groupId> <artifactId>spring-ai-agent-utils-common</artifactId> <version>0.7.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>7.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-client-chat</artifactId> <version>2.0.0-M3</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.vladsch.flexmark</groupId> <artifactId>flexmark-html2md-converter</artifactId> <version>0.64.8</version> <scope>compile</scope> </dependency> </dependencies> </project>

Overview

Spring AI Agent Utils brings Claude Code-inspired tools and agent skills to Spring AI applications. This library reimplements core Claude Code capabilities as Spring AI tools, enabling sophisticated agentic workflows with file operations, shell execution, web access, task management, and extensible agent skills.

Spring AI Agent Utils为Spring AI应用带来了受Claude Code启发的工具与智能体技能。该库重构了Claude Code的核心功能作为Spring AI工具,支持文件操作、命令行执行、网络访问、任务管理等复杂智能体工作流,并具备可扩展的智能体技能体系。

Version: 0.4.0 • Requires Spring AI 2.0.0-SNAPSHOT or 2.0.0-M2

Quick Start

Add Dependency

<dependency> <groupId>org.springaicommunity</groupId> <artifactId>spring-ai-agent-utils</artifactId> <version>0.4.0</version> </dependency>

Configure Your Agent

ChatClient chatClient = chatClientBuilder // System prompt with environment context .defaultSystem(p -> p.text(agentSystemPrompt) .param(AgentEnvironment.ENVIRONMENT_INFO_KEY, AgentEnvironment.info()) .param(AgentEnvironment.GIT_STATUS_KEY, AgentEnvironment.gitStatus())) // Core Tools .defaultTools( ShellTools.builder().build(), FileSystemTools.builder().build(), GrepTool.builder().build(), GlobTool.builder().build(), SmartWebFetchTool.builder(chatClient).build(), BraveWebSearchTool.builder(braveApiKey).build()) // Task Management .defaultTools(TodoWriteTool.builder().build()) // Skills System .defaultToolCallbacks(SkillsTool.builder() .addSkillsDirectory(".claude/skills") .build()) // Sub-Agents .defaultToolCallbacks(TaskToolCallbackProvider.builder() .chatClientBuilder("default", chatClientBuilder.clone()) .subagentReferences(ClaudeSubagentReferences.fromRootDirectory(".claude/agents")) .build()) .build();

Core Tools

FileSystemToolsRead, write, and edit files with precise control:

FileSystemTools.builder() .allowedPaths(List.of("/project")) // Restrict access .build();

Operations:readFile,writeFile,editFile,listDirectory

ShellToolsExecute shell commands with timeout control and background process management:

ShellTools.builder() .defaultTimeout(Duration.ofMinutes(2)) .allowBackgroundProcesses(true) .build();

Features: timeout control, background execution, regex output filtering

GrepToolPure Java grep implementation for code search:

GrepTool.builder() .maxResults(100) .build();

Features: regex patterns, glob filtering, multiple output modes (content, files, count)

GlobToolFast file pattern matching:

GlobTool.builder().build();

Supports patterns like**/*.java,src/**/*.ts

SmartWebFetchToolAI-powered web content summarization with caching:

SmartWebFetchTool.builder(chatClient) .cacheDuration(Duration.ofMinutes(15)) .build();

BraveWebSearchToolWeb search with domain filtering:

BraveWebSearchTool.builder(braveApiKey) .maxResults(10) .build();

User Interaction

AskUserQuestionToolAsk users clarifying questions during agent execution:

AskUserQuestionTool.builder() .questionHandler(questions -> { // Display questions to user, collect answers return answers; }) .build();

Supports multiple-choice options and free-form input.

Task Management

TodoWriteToolStructured task management with state tracking:

TodoWriteTool.builder().build();

Track tasks with states:pending,in_progress,completed

TaskTools (Sub-Agents)Extensible sub-agent system for delegating complex tasks to specialized agents:

TaskToolCallbackProvider.builder() .chatClientBuilder("default", chatClientBuilder) .chatClientBuilder("haiku", haikuBuilder) // Multi-model support .subagentReferences(ClaudeSubagentReferences.fromRootDirectory(".claude/agents")) .skillsDirectories(".claude/skills") .build();

Features:

  • Multi-model routing- Use different models for different sub-agents
  • Pluggable backends- Claude-style, A2A protocol, or custom implementations
  • Background task execution- Run sub-agents asynchronously
  • Task output retrieval- Get results from background tasks

A2A Protocol SupportThe sub-agent architecture supports the A2A (Agent-to-Agent) protocol for interoperability with external agents:

// Custom A2A subagent integration (see subagent-demo example) public class A2ASubagentExecutor implements SubagentExecutor { @Override public String execute(TaskCall taskCall, SubagentDefinition subagent) { AgentCard agentCard = ((A2ASubagentDefinition) subagent).getAgentCard(); // Send message via A2A protocol Client client = Client.builder(agentCard) .withTransport(JSONRPCTransport.class, config) .build(); client.sendMessage(message); // ... } }

The extensible architecture uses three interfaces:

  • SubagentResolver- Discovers and loads sub-agent definitions
  • SubagentExecutor- Executes tasks on sub-agents
  • SubagentDefinition- Describes a sub-agent’s capabilities

Agent SkillsExtend AI capabilities with reusable knowledge modules:

--- name: code-review description: Reviews code for best practices tools: [FileSystemTools, GrepTool] --- # Code Review Skill When reviewing code, check for: 1. Security vulnerabilities 2. Performance issues 3. Code style consistency ...

Load skills from directories:

SkillsTool.builder() .addSkillsDirectory(".claude/skills") .addSkillsDirectory("/shared/skills") .build();

AgentEnvironmentDynamic context utility for system prompts:

.defaultSystem(p -> p.text(systemPrompt) .param(AgentEnvironment.ENVIRONMENT_INFO_KEY, AgentEnvironment.info()) .param(AgentEnvironment.GIT_STATUS_KEY, AgentEnvironment.gitStatus()) .param(AgentEnvironment.AGENT_MODEL_KEY, "claude-sonnet-4-5") .param(AgentEnvironment.AGENT_MODEL_KNOWLEDGE_CUTOFF_KEY, "2025-01-01"))

Provides: working directory, platform info, git status, model information

Examples

ExampleDescription
code-agent-demoFull-featured AI coding assistant with interactive CLI
todo-demoTask management with TodoWriteTool and progress tracking
subagent-demoExtensible sub-agent system with A2A protocol integration
skills-demoCustom skill development with SkillsTool
ask-user-question-demoInteractive agent-user communication

Requirements

  • Java 17+
  • Spring Boot 3.x / 4.x
  • Spring AI 2.0.0-SNAPSHOT or 2.0.0-M2

https://central.sonatype.com/artifact/org.springaicommunity/spring-ai-agent-utils

http://www.jsqmd.com/news/723510/

相关文章:

  • 告别命令行恐惧!用PyCharm专业版+AutoDL,像操作本地文件一样玩转远程服务器
  • 孤舟笔记 并发篇六 死锁是怎么产生的?面试必问的四个条件和三种破解方法
  • 14.深入YOLOv8:CSPDarknet/C2f原理+车辆检测实战+部署优化全攻略
  • Python和Java默认排序算法TimSort,为什么它比快排和堆排更受青睐?
  • SCI/SSCI投稿避坑指南:Cover Letter里这5个细节没写对,编辑可能直接拒稿
  • 【深度解析】从 GPT-5.5 Codex 到百万 Token 上下文:构建可落地的多模型 AI Coding Agent 路由架构
  • 视界新生,多模态破壁 ——DeepSeek 识图模式正式上线
  • 【navicat不安装sql server直接远程连接服务器数据库】
  • ARM MPAM架构解析:资源隔离与QoS控制技术
  • 【深度解析】从人形机器人到 AI 数字分身:可信“合成人”背后的多模态智能架构与工程落地
  • 大语言模型安全对齐与拒绝行为优化实践
  • VLA模型动作退化问题与DUALVLA解决方案
  • PHP开发者速看:Laravel 12原生AI驱动架构详解(内置AI Service Container深度拆解)
  • FlexASIO终极指南:免费解锁Windows专业级低延迟音频体验
  • 有机富硒大米核心技术拆解及靠谱品牌实测推荐:控糖控碳水大米,有机五常大米,有机大米价格,有机大米标准,排行一览! - 优质品牌商家
  • VMware Workstation Pro 17 免费激活终极指南:获取数千个有效许可证密钥的完整教程
  • 从F-22到你的笔记本:揭秘那些藏在消费电子里的“隐形”吸波材料(橡胶垫/泡棉选购指南)
  • 2026 文档解析工具终极选型指南:MinerU vs LlamaParse vs Docling vs Unstructured vs PyMuPDF
  • Tiny-Twin:低成本CPU架构实现5G数字孪生信道仿真
  • 2026年ai智慧图书馆top5推荐:图书馆管理云平台,图书馆自动化管理系统,图书馆自助借还书机,排行一览! - 优质品牌商家
  • 商米港股上市:市值超370亿港元 中专生林喆敲钟 小米浮盈20亿
  • 告别电流采样:用SimpleFOC库实现无感FOC电机控制的保姆级配置流程
  • STM32F4实战:用CubeMX配置SDIO+DMA读写SD卡,附完整代码与常见问题排查
  • 大模型路由技术:智能调度实现成本与性能优化
  • MySQL8四大事务隔离级别详解,彻底搞懂脏读、不可重复读、幻读
  • 【深度解析】Open Design:用本地优先架构重塑 AI UI 生成工作流
  • QT实战:如何用QProcess打造一个带界面的cmd工具(附完整源码)
  • 用OpenCvSharp搞定工业零件涂胶检测:一个C#工程师的实战踩坑与调参心得
  • 如何快速解决Windows热键冲突:完整检测与优化指南
  • 【独家首发】Swoole+LLM双通道保活协议设计(心跳+语义校验+上下文快照):附可商用的376行核心源码及压力测试报告