使用技能
技能是一个带 SKILL.md 的目录:智能体在需要时读取它,获得你的业务规则、流程或脚本。上传一次,挂到任意多个智能体上;改规则时上传新版本,不用改智能体。
准备 Bun 或支持原生 fetch 与 FormData 的 Node.js,以及你所在组织的 API Key(见 API Key)。在服务端设置 PRAXIS_API_KEY,Key 不要放进网页。
上传技能
用 POST /agent/v1/skills 以 multipart/form-data 上传。每个文件一个 files 字段,文件名就是路径,所有文件放在同一个顶层目录下:
refund-policy/SKILL.mdrefund-policy/reference.mdrefund-policy/scripts/check.pySKILL.md 以 frontmatter 开头:
---name: refund-policydescription: Use when a customer asks about refunds. Holds the refund window and the approval code.---
正文:智能体需要这个技能时读到的内容。| 规则 | 说明 |
|---|---|
| 单一顶层目录 | 所有文件路径形如 <目录>/…;目录外的文件、两个不同的顶层目录都返回 400 |
SKILL.md | 必须在 <目录>/SKILL.md,且带 frontmatter;缺失返回 400 |
description | frontmatter 必填。它告诉智能体什么时候该用这个技能,写成「在……时使用」 |
name | 可选,默认取目录名。只能是一个文件夹名:1 到 255 个字符,不含 /、\、NUL,不是 . 或 ..,首尾不能有空格;不合规返回 400 并写明允许的形式 |
display_name | 可选的表单字段,只用于列表展示 |
| 体积 | 总计不超过 8 MB、最多 200 个文件;路径不得含 ..、绝对路径或空段 |
上传创建技能和它的第一个版本,响应带 id(skill_…)和 latest_version_id。版本 ID 是一个递增的不透明字符串,原样使用,不要自己解析。版本不可变:想改内容就上传新版本。
版本与最新版本
POST /agent/v1/skills/{skill_id}/versions 以同样的格式上传新版本。新版本的 SKILL.md 里的 name 必须与技能原来的名字一致,否则返回 400。上传后:
- 技能的
latest_version_id指向新版本,旧版本保持不变,仍可读取和下载。 GET /agent/v1/skills/{skill_id}/versions按新到旧列出版本,每项带该版本SKILL.md里的name和description。GET /agent/v1/skills/{skill_id}/versions/{version}/content下载该版本的 zip。- 删除某个版本后,
latest_version_id回退到剩余的最新版本。
挂载到智能体
在创建或更新智能体时用 skills 挂载,每项是 { "type": "custom", "skill_id": "skill_…", "version"?: "…" }:
| 写法 | 含义 |
|---|---|
省略 version,或写 "latest" | 每次创建会话时取技能当时的最新版本 |
version 填一个版本 ID | 固定在这个版本;技能之后上传新版本也不受影响 |
一个智能体最多挂 20 个技能,同一个 skill_id 不能重复。type 只支持 custom,写 anthropic 返回 400:先上传,再以 custom 挂载。技能或固定的版本必须存在于你的组织。更新时省略 skills 保持原样,传数组整体替换,传 [] 或 null 清空。
挂载写在智能体版本里,所以改挂载也是保存一个新版本。会话启动后,已运行的会话不会因为后来上传的技能版本而改变。
会话里的安装位置
会话带机器时(服务智能体默认使用 node22 环境,见运行环境),每个技能在会话启动时安装到 /home/user/.praxis/skills/<name>/,<name> 是 SKILL.md 里的 name。
- 机器上已有同名技能时,不覆盖,会话收到一条「未安装」提示,先到的同名技能继续生效。
- 没有机器的会话(
environment_id: null)不安装技能。 - 两个技能用同一个
name挂在同一个智能体上时,只会装上其中一个,换一个名字再上传。
删除
| 操作 | 结果 |
|---|---|
| 删除仍被未归档智能体使用的技能 | 409 RESOURCE_IN_USE,消息列出最多 10 个智能体 ID;先从这些智能体移除 |
| 删除未被使用的技能 | 技能连同它的全部版本一起删除 |
| 删除被未归档智能体固定的版本 | 409 RESOURCE_IN_USE |
| 删除技能的最后一个版本 | 409 SKILL_LAST_VERSION:技能至少保留一个版本,要删就删整个技能 |
先改智能体(换版本或移除技能),再删版本或整个技能。
端到端示例
下面的脚本上传一个技能,挂到新智能体,开始会话,让智能体读出只有技能里才有的审批码。保存为 skill-demo.mjs,执行 node skill-demo.mjs。
import assert from "node:assert/strict";import { setTimeout as delay } from "node:timers/promises";
const { PRAXIS_API_KEY } = process.env;assert(PRAXIS_API_KEY, "Set PRAXIS_API_KEY in the server process");const base = "https://api.deepraxis.com/agent/v1";async function request(path, { method = "GET", body, form } = {}) { const response = await fetch(`${base}${path}`, { method, headers: { Authorization: `Bearer ${PRAXIS_API_KEY}`, ...(form ? {} : { "Content-Type": "application/json" }), }, body: form ?? (body === undefined ? undefined : JSON.stringify(body)), signal: AbortSignal.timeout(30_000), }); const result = await response.json(); if (!response.ok) { throw new Error(`HTTP ${response.status}; request=${response.headers.get("X-Request-Id")}; ${result.error?.message ?? ""}`); } return result;}
// 1. Upload the skill: one top-level directory, SKILL.md with frontmatter.const skillMd = `---name: refund-policydescription: Use when a customer asks about refunds. Holds the refund window and the approval code.---
# Refund policy
Refunds are accepted within 30 days of purchase.Read reference.md for the approval code and quote it when asked.`;const form = new FormData();form.append("display_name", "Refund policy");form.append("files", new Blob([skillMd]), "refund-policy/SKILL.md");form.append("files", new Blob(["Approval code: RF-4417\n"]), "refund-policy/reference.md");const skill = await request("/skills", { method: "POST", form });assert(skill.latest_version_id, "The upload creates the first version");console.log({ skill: skill.id, version: skill.latest_version_id });
// 2. Attach it. Omitting version follows the newest version when a session starts.const agent = await request("/agents", { method: "POST", body: { name: "Refund assistant", kind: "service", model: "deepseek-flash", system: "Answer refund questions. Use your skills when they apply.", skills: [{ type: "custom", skill_id: skill.id }], },});assert.equal(agent.skills[0].skill_id, skill.id);
// 3. Start a session and ask for something only the skill knows.const session = await request("/sessions", { method: "POST", body: { agent: { type: "agent", id: agent.id, version: agent.version } },});await request(`/sessions/${session.id}/events`, { method: "POST", body: { events: [{ type: "user.message", content: [{ type: "text", text: "Use the refund-policy skill and tell me the approval code." }] }] },});
// 4. Wait for a reply that is followed by an idle status.const deadline = Date.now() + 180_000;let reply = "";while (Date.now() < deadline && !reply) { const { data } = await request(`/sessions/${session.id}/events?order=asc&limit=100`); const last = data.findLastIndex((event) => event.type === "agent.message"); if (last >= 0 && data.slice(last).some((event) => event.type === "session.status_idle")) { reply = data.filter((event) => event.type === "agent.message") .flatMap((event) => event.content ?? []).map((block) => block.text ?? "").join("\n"); } else await delay(2000);}assert(reply.includes("RF-4417"), `Expected the approval code in the reply, got: ${reply}`);console.log({ session: session.id, reply, verified: true });预期结果: 先输出技能 ID 和版本 ID,最后输出 verified: true,回复中包含 RF-4417。审批码只存在于 reference.md,回复里出现它,就证明技能被安装并被读取了。重新运行会再创建一份技能、智能体和会话;用完按上一节的顺序清理。
失败时检查
| 现象 | 处理 |
|---|---|
400 frontmatter field "description" is required | SKILL.md 缺少 description |
400 <目录>/SKILL.md is required | 目录里没有 SKILL.md,或文件放在了顶层 |
400 files must sit inside one top-level directory | 有文件没有目录前缀,或出现了第二个顶层目录 |
400 skills[0].version … was not found | 版本 ID 不存在或已删除,用 GET /agent/v1/skills/{skill_id}/versions 取值 |
400 skills[0].type anthropic is not supported | 把技能上传后以 custom 挂载 |
| 会话里没有这个技能 | 看事件里的未安装提示:同名技能已在机器上,或会话没有机器 |