AgentSkillsCN

prompting

在为 AI 工具撰写提示词、管理 AI 对话中的上下文,或为 AI 分解任务时,此功能可提供有力支持。

SKILL.md
--- frontmatter
name: prompting
description: Use when crafting prompts for AI tools, managing context in AI conversations, or decomposing tasks for AI

Prompting

Announce at start: "Following the prompting skill for effective AI interaction."

Core Rule

Task first, context after. Lead with what you want, then provide supporting information.

Prompt Structure

1. State the Task Clearly

text
[Specific, actionable task description]

Context:
- [Relevant code or file references]
- [Constraints and boundaries]
- [Expected behavior]

2. Decompose Large Tasks

SignalAction
Task mentions "and" multiple timesSplit on each "and"
Touches more than 2-3 filesDo one file at a time
Multiple behaviors to implementOne behavior per prompt
"While you're at it..."Separate prompt

3. Set Explicit Constraints

text
[Task description]

Constraints:
- Only modify: [specific files or functions]
- Must preserve: [existing behavior, API, tests]
- Don't use: [forbidden dependencies, patterns]
- Must support: [versions, environments, edge cases]

4. Provide Focused Context

DoDon't
Share the specific functions mentioned in the errorDump the entire codebase
Include relevant types and interfacesInclude unrelated modules
Show error messages and stack tracesDescribe errors vaguely
Reference existing patterns to matchAssume AI knows your conventions

Context Management

Session Hygiene

  • Start fresh sessions for unrelated tasks
  • Re-state critical constraints when context grows long
  • Share only code relevant to the current task
  • Summarize decisions made earlier in the session

When Context Gets Stale

SymptomCauseFix
AI forgets instructionsContext pushed outRepeat key constraints
AI contradicts previous outputLost historyStart fresh session
AI ignores shared codeCode too far backRe-share relevant snippets
Generic responsesOverloaded contextReduce scope

Prompt Templates

Bug Fix

text
Fix this error: [full error message]

Stack trace: [full stack trace]

Code: [relevant function]

Expected: [correct behavior]
Actual: [current behavior]

Feature Addition

text
Add [feature] to [component].

Behavior:
- When [trigger], it should [action]

Constraints:
- [Scope limits]
- [What must not change]

Match the pattern in [existing similar code].

Related Skills

WhenInvoke
Prompting for a multi-step taskplanning
Prompting for debugging helpdebugging
Prompting for code reviewcode-review

Deep Reference

For principles, rationale, anti-patterns, and examples:

  • guides/prompting-patterns/prompting-patterns.md
  • guides/context-management/context-management.md