Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Pi Agent Prompt Templates

Pi Agent Prompt Templates

Prompt templates are predefined Markdown snippets that expand into full prompts via short commands, improving efficiency for repetitive work.


Template overview

Prompt templates work simply:

  1. Create a Markdown file defining the template content
  2. Type /template-name in the editor to invoke it
  3. The template automatically expands and fills into the editor

Templates support parameter substitution, allowing the same template to be used in different specific scenarios.


Create a template

A template is a Markdown file with YAML frontmatter.

The filename (without .md) is the template's command name.

Create a code review template:

Example


description: Review current git staged changes

Review the changes in the staging area (git diff --cached), focusing on:

Potential bugs and logic errors

Security Issue

Error handling and edge cases

Performance Issues

After saving to ~/.pi/agent/prompts/review.md, type /review in the editor to expand and use it.


Template locations

Pi Agent looks for templates in several fixed locations, each with a different scope.

Position Scope
~/.pi/agent/prompts/*.md Global templates, available in all projects
.pi/prompts/*.md Project templates, loaded only after the project is trusted
Pi Packages' prompts/ directory Templates in a package
--prompt-template path Temporary load from the command line

Template discovery isnon-recursive, so templates in prompts/ subdirectories are not loaded automatically.

If a template is placed in a subdirectory, you need to explicitly add that path to the prompts array in settings.json.


Parameter system

Templates support a rich parameter system so the same template fits different scenarios:

Syntax Meaning Example
$1, $2, $3... positional parameters $1 represents the first parameter
$@ or $ARGUMENTS Combination of all parameters Join all parameters with spaces
${1:-default} Parameter with a default value Use the parameter if it exists and is non-empty, otherwise use the default value
${@:N} Starting from the Nth parameter ${@:2} takes all parameters from the 2nd onward
${@:N:L} Take L parameters starting from the Nth ${@:2:3} takes parameters 2-4

$ARGUMENTS concatenates all parameters verbatim, suitable for templates that just need a whole block of text:

Example


description: Translate a piece of Chinese into idiomatic English

argument-hint: ""

Translate the following content into idiomatic English, output only the translation:

$ARGUMENTS

After saving as ~/.pi/agent/prompts/translate.md, use /translate to translate this passage into English.

Example of a template with parameters

The template below combines positional and trailing parameters, suitable for inputs like "type + name + additional description".

Example


description: Create a component using the specified framework

argument-hint: " [feature description]"

Create a $2 component using $1, with features including: $

{

@:3

}

$1 takes the first parameter as the framework, and $2 takes the second as the component name.

${@:3} represents all content from the third parameter onward, used to carry scattered feature descriptions.

Usage:



/component React Button "onClick 事件处理" "disabled 状态支持" "loading 加载状态"

Result after expansion:



使用 React 创建一个 Button 组件,功能包括:onClick 事件处理 disabled 状态支持 loading 加载状态

Default value example

When a parameter is missing, the default value serves as a fallback, so the template works even when called without parameters.

Example


description: Summarize current project status

Use $

{

1:-5

}

key points to summarize the project's main changes and status.

After saving to ~/.pi/agent/prompts/summarize.md, invoke with /summarize.

Using /summarize outputs 5 key points by default.

Using /summarize 10 outputs 10 key points.

The expansion results of the two calls are compared below:



/summarize

→ 用 5 个要点总结当前项目的主要变更和状态。



/summarize 10

→ 用 10 个要点总结当前项目的主要变更和状态。


argument-hint parameter hints

Setting argument-hint in the frontmatter helps users understand the parameters a template needs:

Example


description: Review a PR from a URL, analyzing code and issues

argument-hint: ""

Review the code changes in the following PR, focusing on security and performance issues: $1

In the autocomplete dropdown, this template appears as:



→ pr     — 从 URL 审查 PR,分析代码和问题

After saving to ~/.pi/agent/prompts/pr-review.md, invoke with /pr-review https://github.com/runoob/repo/pull/12.

Use indicate required parameters; [square brackets] indicate optional parameters.


Practical template examples

The following three templates cover the three most common request types in daily development; copy them and adjust as needed.

Git commit message generation

The following template generates commit messages following the Conventional Commits convention.

Example


description: Generate a conventional commit message from git diff

Review the content of git diff --cached and generate a conventional git commit message.

Follow the Conventional Commits convention, format: type

(

scope

)

: description

Types include: feat, fix, refactor, docs, test, chore

After saving to ~/.pi/agent/prompts/commit.md, stage changes and invoke with /commit.

Code refactoring request

The following template breaks refactoring goals into clear checklist items to prevent the AI from only changing formatting without touching structure.

Example


description: Refactor a specified code module

argument-hint: ""

Refactor the code of $1, with goals:

Improve code readability

Eliminate duplicate code

Improve error handling

Keep existing functionality unchanged

Explain your refactoring plan before making changes.

After saving to ~/.pi/agent/prompts/refactor.md, invoke with /refactor src/utils/date.ts.

Bug fix request

The following template forces the AI to troubleshoot in fixed steps, reducing the tendency to "start changing code right away".

Example


description: Systematically investigate and fix a specified Bug

argument-hint: ""

I need you to help me investigate and fix the following Bug: $1

Please proceed according to the following steps:

First understand the Bug's expected and actual behavior

Locate the relevant code files

Analyze possible causes

Propose a fix

Implement the fix

Verify the fix is correct

Explain your findings and reasoning at every step.

After saving to ~/.pi/agent/prompts/fix-bug.md, invoke with /fix-bug List not refreshing after login.


Template loading rules

Template discovery and loading follow these rules; check here first when troubleshooting "a template not showing up".

Rule Description
Non-recursive discovery Template discovery in the prompts/ directory is non-recursive; templates in subdirectories are not discovered automatically
Subdirectories must be declared explicitly To load templates in a subdirectory, explicitly add the path to the prompts array in settings.json
description fallback If description is empty, Pi Agent uses the first non-empty line of the file as the description
Disable automatic discovery Disable automatic discovery with --no-prompt-templates, but templates explicitly specified with --prompt-template still load

If a template doesn't appear in the completion list after you type /template-name, first confirm the file is in the prompts/ root directory.

Project templates placed in .pi/prompts/ also need to pass the project trust check first, otherwise they won't be loaded either.