AgentSkillsCN

context-engineering-basics

精通上下文工程:统一结构、元数据驱动的发现、压缩、即时加载,以及多智能体内存管理。 在以下场景中使用:架构AI系统、优化Token使用、设计多智能体工作流,或管理复杂的上下文窗口。

SKILL.md
--- frontmatter
name: context-engineering-basics
description: |
  Master context engineering: unified structures, metadata-driven discovery, compression, JIT loading, and multi-agent memory management.
  Use when: architecting AI systems, optimizing token usage, designing multi-agent workflows, or managing complex context windows.

Context Engineering Basics

Context Engineering is the discipline of curating the "mental state" of an AI model. It determines whether an agent is a genius or a hallucination engine.

How to design a Unified Context Structure

Use a tiered file structure (like .context/) to organize information by authority.

  • T0 (Constitution): Absolute rules.
  • T1 (Standards): Normative guidelines.
  • T2 (Context): Informative project data.

Crucial: Use high-quality Metadata (filename + frontmatter description) for every file. The AI uses these as "semantic hooks" to decide what to read.

See Context Structure & Metadata for the full template and metadata guide.

How to optimize Token Usage

Tokens are money and latency.

  • Compression: Minify data formats (JSON -> YAML) and summarize history.
  • Prompt Caching: Structure prompts with static prefixes to leverage cache hits.
  • JIT Loading: Load detailed context only when triggered by keywords.

See Optimization Techniques for compression algorithms and caching strategies.

How to manage Memory (Single vs. Multi-Agent)

Memory strategies differ significantly by architecture:

  • Single Agent: Monolithic context window with sliding window or summary.
  • Multi-Agent: Distributed context. Each agent has private "Working Memory" and accesses a shared "Knowledge Base".

See Memory Management for consolidation patterns and multi-agent workflows.

Common Pitfalls & Warnings

ErrorConsequenceFix
Vague MetadataAgent fails to find relevant docs.Ensure description contains specific keywords/triggers.
Context Flooding"Lost in the Middle" phenomenon.Use JIT loading; don't dump all files at once.
Shared State PollutionIn multi-agent, one agent confuses another.Isolate Working Memory; use explicit message passing.

Useful Scripts

  • scripts/load-context.sh: Example script to aggregate context based on Tiers.

References