96SEO 2026-08-12 04:59 46
当你把 Agent 的功能拆成一个个独立的 skill 时能获得以下好处:
痛点提示:如果缺乏统一规范,新手很容易在同一项目中重复创建同名 skill;不过,团队成员修改后的 skill 在其他项目里可能被误用或覆盖。按理说,

先用最朴素的方式跑通:一个目录里放若干 skill 文件夹。agent 启动时把所有 skill 加载进 prompt。先看一个 skill 长什么样。
---name: git-commit
description: 团队约定的 git commit message 格式与示例。当使用者让你 commit 改动、写提交信息、调整 commit message 时使用。---
# Git Commit 规范
我们用 conventional commit + scope,scope 必须是 packages/ 下的目录名。## 格式
:
- type: feat / fix / refactor / chore / docs / test
- scope: 受影响的 package,如 `agent` / `backend`
- subject: 祈使句,不带句号,不超过 ...
## 示例
...
说到约定就两条。
name 和 description. name 是 skill 的稳定 id,description 是给 LLM 看“什么时候用我”。痛点提示:如果忘记提供 name 或 description,会导致该 skill 永远无法被触发。
MOST DIRECT WAY:起 agent 之前扫一遍 skills 目录。把所有 S.KILL.md 读出来body 全部拼到 system prompt 尾巴上。按理说,我们用第四篇定义的 middleware 接口挂在 beforeAgentRun 钩子上。
import matter from 'gray-matter';其实,interface Skill { name:string;description:string;说起来,body:string;path:string,}
function createSkillsMiddleware: AgentMiddleware {
let loadedSkills:Skill=;return {
beforeAgentRun:{ async =>{
const {sandbox}=agentContext;const entries=await sandbox.listDir.catch=>);不过,const skills:Skill=;for{
if) continue;const skillPath=`${skillsDir}/${entry.path}/SKILL.md`;const content=await sandbox.readFile.catch=>null);if continue,const parsed=matter;skills.push({
name这方面,parsed.data.name。description:parsed.data.description,body:parsed.content,path:skillPath,});}
loadedSkills=skills;}},beforeModel:{=>{
if return;const skillSections=loadedSkills.map.join;return {prompt:`${modelContext.prompt}
# Available Skills
${skillSections}`};}},},}
痛点提示:每一次 LLM 调用都携带全部技能内容。即使只用了其中一个,也会产生大量无效 token 消耗。
The main problem is that we pre-decide “all skills must be seen”,while in reality each turn usually uses only a handful of m. The next section introduces a smarter approach.
The core idea is to expose only metadata in system prompt and let model decide wher to fetch a particular body via built‑in ``read_file` tool. This way token cost drops from “sum of all bodies” to “sum of actually used bodies”.
function createSkillsMiddleware: AgentMiddleware {
let loadedSkills:Array<{name:string,description:string,path:string}>=;return {
beforeAgentRun:{ async =>{
const {sandbox}=agentContext;const entries=await sandbox.listDir.catch=>);const skills=;for{
if) continue;const skillPath=${skillsDir}/${entry.path}/SKILL.md;const content=await sandbox.readFile.catch=>null);if continue,// parse only frontmatter
const parsed=matter;skills.push({
说到name,.name。description:.description,path:skillPath,});}
loadedSkills=skills;
}},beforeModel:{=>{
if return;return {prompt:${modelContext.prompt}
${buildSkillSystemPrompt)}};}},},}
function buildSkillSystemPromptstring{
return You have access to several specialized workflows called Skills.
Each Skill lives in its own folder and its main file is referenced by \ path` below.
When your task matches a Skill's `description`,immediately call `read_file` on that `path`. Only load what you really need.
Do not pre-load irrelevant Skills.
${JSON.stringify}
<\/skill_system>`;说起来,}
Emphasize key differences: 1️⃣ Only keep frontmatter. 2️⃣ Inject JSON metadata + instruction template into system prompt.
Pain Point Alert:;Without this change you’re paying huge costs for every unused skill’s body—just think about dozens of hundreds‑line SKILL.md files being sent over and over again!
| 场景 | 第一版 | 第二版 |
|---|---|---|
| 程序 Prompt 字符数 | N × avgBodyLength + ... |
N × avgMetaLength + 指令模板长度 |
| 每次 LLM 调用 | 包含所有 N×avgBodyLength 字符 |
包含少量元数据;实际使用时额外一次 read_file |
If an entire conversation only uses two out of thirty-two Skills,second version’s Prompt size shrinks by roughly N/30–N/10 times – dramatically cutting token cost and inference latency.
The next section dives deeper into crafting effective descriptions so se downsides vanish.
Because Gradual Loading treats LLM as a router that decides which Skill body to fetch based on descriptions alone。a poorly written description renders whole mechanism useless.
”,没说明何时使用
yaml
description: Git commit message format doc
LLM doesn’t know when it should apply this rule. ✅ Good example:
description: 团队约定 git commit message 格式与示例。在使用者请求提交改动、写 commit message 或调整已有 commit 时使用。
关键词匹配即可,无需深度语义推理。
2️⃣ 列举过多功能却没限定场景
description: 包含组件命名、目录结构、CSS 写法、状态管理、props 类型、hooks 使用规范
在任何 React 编码场景都会匹配,但真正只有少数规则被触及。再看解决办法,细化为单独 Skills 或明确限定使用范围。例如 “适用于本仓库 frontend 模块”。
3️⃣ 过长且像产品文档
LLM 在程序 Prompt 中扫描所有描述。若每条超过200字,多条累积就形成新的 Token 爆炸。保持描述简洁即可,
yaml ---name: company-api--- description: 调用公司内部 ai-platform API 的认证、签名、错误码规范。当使用者请求调用 ai-platform 接口、
所有请求需要在 header 带 X-Tenant-Id 和 Authorization Bearer /v1/auth/token 换取。
| code | 含义 | 对应处理 |
|---|---|---|
| token_expired | Token 已过期 | 换取 |
| rate_limited | 限流 | 指数退避重试 |
完整可跑客户端代码见同目录下 client-example.ts.
Notice how first sentence tells what it does and second sentence lists explicit trigger scenarios—exactly what LLM needs.
从更宏观来看。一个 Skill 并非传统意义上的工具,而是“一段可寻址提示词+配套资源”。其价值体现在的观点是,
一旦模型拿到 Body,就可以继续利用已有 builtin 工具完成后续工作。只要正确建立 Metadata 与 Body,即可明显提高 Agent 能力边界而无需 主要业务逻辑。
至此我们的技能程序已经完整,但仍只支持单个根目录。在实际项目中,你可能有:
三层优先级可以按需求调节。我们实现了一个支持多个方法而且遵循“后者覆盖前者”的中间件。
typescript
function createSkillsMiddleware: AgentMiddleware{
let loaded:Array<{name:string。desc:string,path:string}>=;return {
beforeAgentRun:{ async =>{
const {sandbox}=agentContext;const map=new Map<string,{name:string,desc:string。path:string}>
for{
const entries=await sandbox.listDir.catch=>);for{
if) continue;const p=`${dir}/${e.path}/SKILL.md`;const c=await sandbox.readFile.catch=>null);if continue,const fm=matter;map.set(fm.data.name,{
name的观点是,fm.data.name。desc:fm.data.description,path:p});}
}
loaded=,}},beforeModel:{=>{
ifreturn;return {prompt:`${modelContext.prompt}
${buildSkillSystemPrompt}`};}}
},}
Key changes: 1️⃣ 参数从单方法变成方法数组;2️⃣ 利用 Map 收集同名 Skill,并让后面出现的一致覆盖前面。
javascript
const agent=createAgent({
model。sandbox,middlewares:)
]
});
Now you can locally override a team default just by placing a new folder under .agent/skills;or projects remain unaffected.
The middleware never cares wher lives on disk or inside microVM—thanks to sandbox.listDir/readFile. In dev mode those paths resolve locally;in production y point into /opt/...,/home/...。or git‑cloned project directories .
Thus one piece of code works everywhere without modifications.
js
// No external knowledge needed
const agent=createAgent]});
Passing an empty array means no loop runs during startup and no extra tokens are added—useful when running unit tests or lightweight agents.
After this article code‑artisan now has an extensible “plug‑in” layer:
This design shifts Agent’s capability boundary from hardcoded logic into runtime‑loadable resources—a consistent evolution alongside our earlier middleware/sandbox patterns that keep core loops lean.
Upcoming post will tackle building a todo system: turning long tasks into plan‑scoped steps with real-time progress tracking using exactly same middleware interface.
All source lives on GitHub . If this helps your workflow feel free ⭐️!
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback