
Pi实战 02提示词与技能篇——把重复工作固化成命令来源Pi 官方 Prompt Templates / Skills 文档以及社区热门技能impeccable、mattpocock/skills。如果你每天都在重复同样的指令——“先写测试”“按这个模板建 API”“帮我 review 这个 PR”——那就别每次手打。Pi 有两种固化方式Prompt Templates提示词模板把一段提示词变成/xxx斜杠命令支持参数。适合一句话触发一段固定流程。Skills技能自包含的能力包SKILL.md 脚本 资源按需加载。适合一整套带脚本的工作流。一句话区别composio.dev 总结得很准Skills teach the agent技能教会 AgentExtensions extend the agent扩展扩展 Agent。一、Prompt Templates自定义/xxx命令1. 创建一个模板mkdir-p~/.pi/agent/promptsvim~/.pi/agent/prompts/review.md文件内容frontmatter 正文--- description: Review the last change --- Review the most recent changes in this repo. Focus on: 1. Correctness and edge cases 2. Security issues (injection, auth, secrets) 3. Readability Point out problems only — dont rewrite unless I ask.用法在输入框敲/review自动补全会显示描述回车即展开。2. 带参数的模板Pi 的位置参数语法和 shell 很像语法含义$1$2第 1、2 个位置参数$所有参数整段剩余输入$ARGUMENTS同$${1:-default}带默认值的参数${3:text}仅当第 3 个参数存在时才插入text${:N}/${:N:L}从第 N 个起 / 取 N 开始长度为 L官方示例 A调试命令/debug--- description: Debug an issue --- Debug this issue: $ Steps: 1. Identify the root cause 2. Explain why it happens 3. Propose a fix 4. Consider edge cases 5. Suggest prevention strategies用法/debug Login fails when username contains spaces官方示例 B建组件/component--- description: Create a component --- Create a React component named $1 with features: $用法/component Button onClick handler disabled support官方示例 C条件参数${3:...}--- description: Create API endpoint --- Create a $1 API endpoint at $2${3: with authentication}. Implement: - Request validation - Error handling - Response formatting ${3:- Authentication checks}${3: with authentication}只有在提供了第 3 个参数时才会插入 “with authentication”。官方示例 D默认值${1:-7}--- description: Summarize state --- Summarize the current state in ${1:-7} bullet points.不传参数就用 7 条传了就覆盖。3. 用完后校验/validate-prompts这个命令会重新加载项目和全局提示词目录校验 frontmatter、include 路径、循环引用、保留命令名、以及技能引用能否解析。改完模板跑一下避免拼错导致命令失效。4. 懒得手写让 Pi 自己造在会话里直接说“Create a custom prompt for code review. Make it detailed and very thorough.”Pi 会读它自己的 prompt-template 文档然后生成一个符合规范的.md文件。生成后再按需改参数即可。二、Skills按需加载的能力包1. Skills 怎么工作启动时 Pi 扫描技能目录提取每个技能的name和description。这些元信息以 XML 形式塞进系统提示词。当任务匹配某个技能时Agent 用read或bash加载完整SKILL.md来执行。⚠️ 模型不一定主动读SKILL.md。两种办法强制它读在提示词里明确要求或直接/skill:name。2. 命名规则容易踩坑1–64 字符仅小写字母、数字、连字符-不能以-开头或结尾不能连续-✅ pdf-processing >3. 一个 SKILL.md 长什么样--- name: my-skill description: What this skill does and when to use it. Be specific. --- # My Skill ## Setup Run once before first use: bash cd /path/to/skill npm installUsage./scripts/process.shinputSee the reference guide for details. 关键**用相对路径引用脚本和资源**这样技能目录挪位置也能跑。 ### 4. 社区热门技能可直接装 **impeccable** —— 给 Pi 一套真正的前端设计系统而不是空泛的让它好看点。做前端的必装。 **mattpocock/skills** —— 引入正规 TDD 工作流、鼓励质疑弱假设、先推理再实现。安装 bash npx skillslatest add mattpocock/skills -a pi -g-a pi指定给 Pi-g全局安装让 Pi 自己建技能直接说为我的场景建个技能它连SKILL.md、脚本、文档一起生成。三、实战组合把建 API变成一条龙假设你天天建 REST 端点。配一个/endpoint模板--- description: Scaffold a REST endpoint --- Scaffold a $1 endpoint at $2. 1. Add route handler 2. Validate input with Zod 3. Write one happy-path and one error test 4. Run: npm run typecheck npm test用法/endpoint GET /users/:id/handler—— 一次触发写代码 校验 测试 跑检查整条链不用分四次说。四、避坑小结模板名 命令名别和内置命令撞名/validate-prompts会报 reserved command names。技能描述要具体写什么时候用否则 Agent 匹配不到。技能默认不主动加载全文记得用/skill:name或提示词强制读取。模板/技能改完/reload或/validate-prompts确认生效。上一篇01 · 配置篇 下一篇03 · 扩展篇