什么是 Agent Skills(智能体技能)?
Agent Skills(技能)是一种轻量级、开放式的格式,用于通过专业知识和工作流来扩展 AI 代理(Agent)的能力。
其核心是一个包含 SKILL.md 文件的文件夹。该文件包含元数据(至少包括名称和描述)以及告知代理如何执行特定任务的指令。技能还可以捆绑脚本、参考资料、模板和其他资源。使用 YAML frontmatter + Markdown 正文 的格式。当 LLM 判断需要某个 Skill 时,会调用 skill 工具加载它,SKILL.md 的全部内容会作为 tool-result 注入到对话上下文中,LLM 读到后自主决定怎么执行。
my-skill/
├── SKILL.md # 主文件(必须)
├── scripts/ # 可执行脚本(可选)
├── references/ # 详细参考文档(可选,按需加载)
├── resources/ # 模板、清单等资源(可选)
└── examples/ # 示例(可选)官网
https://agentskills.io/home#what-are-agent-skills
引入AgentUtils
<dependency>
<groupId>org.springaicommunity</groupId>
<artifactId>spring-ai-agent-utils</artifactId>
<version>0.4.2</version>
</dependency>SpringAI
2.0.0-M2+版本支持
Agent-Utils
0.4.2
项目创建问候Skill
mcp-agent/src/main
├── java # 必要的Java代码
├── resources/application.yml # 项目配置文件
├── resources/skill.greeter # Skill文件夹
└── resources/skill.greeter/SKILL.md # Skill主文件SKILL.md内容
---
name: greeter
description: 当用户需要向某人打招呼或说你好时使用此技能
---
## 指令
请使用友好的语气生成问候语。如果是中文名字,可以加上“同学/先生/女士”
;如果是英文名字,直接问候即可。
示例:
- 输入:“问候 张三” -> 输出:“你好,张三同学!欢迎使用 Spring AI Skills Demo!”
- 输入:“问候 Alice” -> 输出:“Hello, Alice! Welcome to Spring AI! Skills Demo”
- 返回内容必须包含【我是Skill回复】这几个字。Config加载Skill
import cn.ydxiaoshuai.mcp.tools.MCPQWeatherTools;
import org.springaicommunity.agent.tools.SkillsTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
/**
* @ClassName AgentChatClient
* @description:
* @author: 小帅丶
* @create: 2026年5月10日14:50:16
* @Version 1.0
**/
@Configuration
public class
AgentChatClientSkillsConfig {
@Bean("agentChatClientSkills")
public ChatClient agentChatClientSkills(ChatModel chatModel,MCPQWeatherTools weatherTools){
ClassPathResource skills = new ClassPathResource("skills");
if (!skills.exists()) {
throw new IllegalStateException("Skills dir missing: " + skills);
}
return ChatClient.builder(chatModel)
.defaultSystem("""
你是一个智能助手。
你可以使用技能(Skills)来完成用户请求。
如果有合适的技能,请优先使用技能而不是自己编造答案。
""")
.defaultToolCallbacks(
SkillsTool.builder()
.addSkillsResource(skills)
.build()
)
.defaultTools(weatherTools)
.defaultAdvisors(new SimpleLoggerAdvisor())
.build();
}
}Controller调用并SSE返回
@RestController
@RequestMapping("/agentChatSkills")
public class AgentChatSkillsController {
@Autowired
@Qualifier("agentChatClientSkills")
private ChatClient chatClient;
@GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> stream(@RequestParam(defaultValue = "向张三打个招呼") String message,
HttpServletResponse response) {
response.setCharacterEncoding(CharsetUtil.UTF_8);
return chatClient.prompt()
.user(message)
.stream()
.content();
}
}看下调用效果

END
Java 也能丝滑玩 AI