AI Agent Skills 开发者指南 2026 版
AI Agent Skills 是构建 AI Agent 技能的框架。从 Skill 定义到部署。2026 开发者必读指南。
- ⭐ 3400
- Python
- YAML
- MIT
- 更新于 2026-05-18
什么是 AI Agent Skills? #
AI Agent Skills 是构建 AI Agent 技能的框架。把「能力」模块化。从定义 Skill 到部署运行。
目录结构 #
my_skill/
├── SKILL.md # 文档
├── skill.py # 实现
├── tests/ # 单元测试
└── examples/ # 使用示例
SKILL.md 格式 #
---
name: 天气查询
description: 查询全球城市天气
tags: ["weather", "api", "daily"]
version: 1.0.0
author: your-name
date: 2026-05-18
---
## 功能描述
查询指定城市的当前天气。
## 使用方法
```python
from skill import WeatherSkill
skill = WeatherSkill()
result = skill.run("北京")
返回格式 #
{"temp": 22, "condition": "晴天", "humidity": 65}
## 创建 Skill
### 使用 Hermes
```bash
hermes skills create weather-query
手动创建 #
mkdir -p weather-query
touch weather-query/SKILL.md
touch weather-query/skill.py
Skill 实现 #
Python 示例 #
import requests
class WeatherSkill:
name = "天气查询"
description = "查询城市天气"
def __init__(self, api_key: str):
self.api_key = api_key
def run(self, city: str) -> dict:
url = f"https://api.weather.com/v1/weather"
params = {"city": city, "key": self.api_key}
response = requests.get(url, params=params)
return response.json()
集成记忆 #
from agent_memory import MemoryMixin
class WeatherSkill(MemoryMixin):
def run(self, city: str) -> dict:
key = f"weather:{city}"
cached = self.cache.get(key)
if cached:
return cached
result = self._fetch_weather(city)
self.cache.set(key, result, ttl=3600)
return result
部署流程 #
1. 编写代码 #
# skill.py
from base_skill import BaseSkill
class MySkill(BaseSkill):
def execute(self, params: dict) -> dict:
return {"result": "hello"}
2. 编写测试 #
def test_skill():
skill = MySkill()
result = skill.execute({"name": "test"})
assert result["result"] == "hello"
3. 集成到 Agent #
from agent import Agent
from skills import MySkill
agent = Agent(skills=[MySkill])
response = agent.run("调用我的 Skill")
高级功能 #
并行执行 #
from concurrent.futures import ThreadPoolExecutor
skills = [Skill1(), Skill2(), Skill3()]
with ThreadPoolExecutor() as executor:
results = list(executor.map(lambda s: s.run(data), skills))
错误处理 #
from skill.exceptions import SkillError
try:
result = skill.run(data)
except SkillError as e:
result = skill.fallback(data)
版本管理 #
# 版本化
git tag v1.0.0
# 更新
pip install my-skill==1.1.0
常见问题 #
Q: Skill 会超时吗?
答:支持超时控制。skill.run(data, timeout=30)。
Q: 如何分享 Skill?
答:发布到 PyPI,或分享 Git 仓库链接。
Q: 支持异步调用吗?
答:支持。async def run() → await skill.run()。
总结 #
AI Agent Skills 把「能力」变成「可插即拔」的组件。代码即技能。
参考:ai-agent-skills.org 文档 更新:2026-05-18
💬 留言讨论