AgentSkillsCN

prompt-context-efficiency

提示词的上下文管理与 FinOps 模式。适用于优化 Token 预算、处理大型输入,或设计上下文高效的提示词时使用。

SKILL.md
--- frontmatter
name: prompt-context-efficiency
description: Context management and FinOps patterns for prompts. Use when optimizing token budget, handling large inputs, or designing context-efficient prompts.

Context Efficiency Patterns

Apply these patterns when generating prompts that handle large inputs or need token-aware design.


The Context Budget Mindset

Think of context window as a budget, not a limit:

Context TypeToken CostSignal ValueStrategy
System promptFixedHighInvest here — drives all outputs
User queryLowCriticalAlways include fully
Reference codeVariableMedium-HighFilter to relevant sections
Logs/outputHighOften LowAggressive filtering
Search resultsHighVariableDedupe, rank, truncate
Tool schemasMediumLow per-callLoad on-demand

Golden rule: Every token should earn its place.


Pattern 1: Progressive Disclosure

Structure prompts to fetch detail incrementally:

xml
<context_strategy>
PHASE 1 — Orientation (minimal context):
- Provide file structure / function signatures only
- Ask: "Which areas need deeper investigation?"

PHASE 2 — Targeted deep-dive:
- Fetch only the identified relevant sections

PHASE 3 — Synthesis:
- Work with focused, relevant context only
</context_strategy>

Pattern 2: Input Preprocessing

Tell the model HOW to handle large inputs:

xml
<input_handling>
FOR LOGS:
- Skip repetitive entries (keep first + count)
- Focus on: errors, warnings, state transitions
- Ignore: debug spam, health checks

FOR CODE:
- Prioritize: signatures, class definitions, error handling
- Skim: boilerplate, imports
- Deep-read: business logic, custom implementations

FOR SEARCH RESULTS:
- Deduplicate similar findings
- Rank by relevance, summarize patterns
</input_handling>

Pattern 3: Relevance Boundaries

Explicitly scope what context matters:

xml
<relevance_scope>
INCLUDE:
- Files in `src/modules/{module_name}/`
- Error messages containing "{pattern}"

EXCLUDE:
- Test files (unless debugging tests)
- Generated code in `*_generated/`
- Unrelated modules
</relevance_scope>

Pattern 4: Output Token Management

xml
<output_efficiency>
RESPONSE SIZING:
- Simple questions → 1-3 sentences
- Code changes → diff-style or minimal replacement
- Analysis → structured summary

AVOID:
- Repeating the question back
- Explaining what you're about to do
- Including unchanged code around edits
- Verbose transitions
</output_efficiency>

Anti-Patterns: Context Waste

Waste PatternCostFix
Full file for one function10-100xUse line ranges or grep
All search results unfiltered5-20xRank, dedupe, limit
Repeated context across turns2-5xReference previous
Tool schemas "just in case"1.5-3xLoad on-demand
Verbose CoT for simple tasks2-4xMatch depth to complexity