Spring AI Agent Utils _ Spring Agent 工具库 用Java开发 Agent 的全套工具集https://blog.csdn.net/D1237890/article/details/160636082Spring 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 version1.0 encodingUTF-8? project xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance modelVersion4.0.0/modelVersion groupIdorg.springaicommunity/groupId artifactIdspring-ai-agent-utils/artifactId version0.7.0/version namespring-ai-agent-utils/name descriptionSpring AI Agent Utilities/description urlhttps://github.com/spring-ai-community/spring-ai-agent-utils/url organization nameSpring AI Community/name urlhttps://github.com/spring-ai-community/url /organization licenses license nameApache License 2.0/name urlhttps://www.apache.org/licenses/LICENSE-2.0/url /license /licenses developers developer nameChristian Tzolov/name /developer /developers scm connectiongit://github.com/spring-ai-community/spring-ai-agent-utils.git/connection developerConnectiongitgithub.com:spring-ai-community/spring-ai-agent-utils.git/developerConnection urlhttps://github.com/spring-ai-community/spring-ai-agent-utils/url /scm dependencies dependency groupIdorg.springaicommunity/groupId artifactIdspring-ai-agent-utils-common/artifactId version0.7.0/version scopecompile/scope /dependency dependency groupIdorg.springframework/groupId artifactIdspring-web/artifactId version7.0.1/version scopeprovided/scope /dependency dependency groupIdorg.springframework.ai/groupId artifactIdspring-ai-client-chat/artifactId version2.0.0-M3/version scopeprovided/scope /dependency dependency groupIdcom.vladsch.flexmark/groupId artifactIdflexmark-html2md-converter/artifactId version0.64.8/version scopecompile/scope /dependency /dependencies /projectOverviewSpring 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-M2Quick Start​Add Dependencydependency groupIdorg.springaicommunity/groupId artifactIdspring-ai-agent-utils/artifactId version0.4.0/version /dependency​Configure Your AgentChatClient 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 ToolsFileSystemToolsRead, write, and edit files with precise control:FileSystemTools.builder() .allowedPaths(List.of(/project)) // Restrict access .build();Operations:readFile,writeFile,editFile,listDirectoryShellToolsExecute 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 filteringGrepToolPure 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-agentsPluggable backends- Claude-style, A2A protocol, or custom implementationsBackground task execution- Run sub-agents asynchronouslyTask 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 definitionsSubagentExecutor- Executes tasks on sub-agentsSubagentDefinition- 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​ExamplesExampleDescriptioncode-agent-demoFull-featured AI coding assistant with interactive CLItodo-demoTask management with TodoWriteTool and progress trackingsubagent-demoExtensible sub-agent system with A2A protocol integrationskills-demoCustom skill development with SkillsToolask-user-question-demoInteractive agent-user communication​RequirementsJava 17Spring Boot 3.x / 4.xSpring AI 2.0.0-SNAPSHOT or 2.0.0-M2https://central.sonatype.com/artifact/org.springaicommunity/spring-ai-agent-utils