context-engineering
npx skills add https://github.com/fzozyurt/langchain-deepagents-skills --skill context-engineering
Agent 安装分布
Skill 文档
Context Engineering Skill
Context Engineering is the process of curating and structuring the information provided to an LLM to optimize its performance. In the DeepAgents framework, this is achieved through the Filesystem-as-RAM pattern and advanced prompt orchestration.
1. The Golden Rule of Context
Information Density > Information Volume. An LLM with 2,000 tokens of perfectly pruned context will outperform an LLM with 128,000 tokens of “noisy” context.
2. Core Patterns
A. Selection & Pruning (The “Needle” Strategy)
Do not provide entire files if only a function is needed.
- Pattern: Use
greporsedtools to extract specific lines. - DeepAgents Implementation: Use the
FilesystemMiddlewareto interceptread_filecalls and suggest targeted reading.
B. Compression & Summarization
Convert verbose logs or documentation into structured metadata.
- Pattern: Before passing a large tool result to the parent agent, use a “Summarizer” Sub-Agent to extract:
- Key Findings.
- Errors/Warnings.
- Suggested Next Steps.
C. Context Ordering (Lost-in-the-Middle Defense)
LLMs prioritize information at the beginning and end of the prompt.
- Primacy Bias: Place core instructions and constraints at the very top.
- Recency Bias: Place the current tool output and the specific user query at the very bottom.
- Middle: Place background knowledge and non-critical reference data in the middle.
D. Structured Delimiters
Use XML-style tags to separate different types of information. This prevents the model from confusing “Knowledge” with “Instructions”.
<instructions>
Update the user profile logic.
</instructions>
<current_context>
File: /workspace/auth.py
Content: [content here]
</current_context>
<background_skills>
[Skills from the /skills/ directory]
</background_skills>
3. The “Context-on-Disk” Workflow
DeepAgents implements the Lazy Loading pattern:
- Step 1: LS: Run
ls -Rto see the structure. - Step 2: Grep: Search for keywords to find the “needle”.
- Step 3: Targeted Read: Only read the relevant 50 lines.
- Step 4: Pin/Unpin: The harness automatically evicts (unpins) large results after they are processed by a thought block.
4. Advanced: Long-Context Strategies
When working with very large repos or deep memory:
- Graph-based Navigation: Use the planning tool to maintain a “Map” of the context, so the agent always knows where to look next without re-reading.
5. Advanced Context-Aware Reasoning
Deepen the model’s interaction with the context using these advanced prompting techniques:
A. Least-to-Most Prompting
Instead of solving a complex task at once, force the model to decompose it into a sequence of simpler subproblems and solve them incrementally.
- Pattern: “First, list the sub-tasks needed to solve X. Then, solve the first sub-task. Use that result to solve the second…”
B. Self-Notes (Interleaved Reasoning)
Force the model to take “internal notes” while reading long contexts. This helps the model maintain focus and avoid skipping details.
- Pattern: “While reading the following text, write [Note: …] every time you encounter a key variable or logic branch.”
C. Directional Stimulus Prompting
Provide a “guidance hint” or “key concept” alongside the context to steer the model’s focus without being overly restrictive.
- Pattern: “Task: Summarize. Context: [Text]. Guidance Hint: Focus specifically on the economic impact.”
D. Active-Prompt (Dynamic Selection)
In few-shot scenarios, use the most “informative” or “uncertain” examples rather than random ones. This is achieved in DeepAgents via the SemanticSimilarityExampleSelector with a diversity filter.
6. Token Budgeting & Caching
A. Context Caching
For production agents with long system prompts or static knowledge bases, use Prompt Caching (e.g., Anthropic Cache, OpenAI Prefilling) to reduce costs and latency.
- DeepAgents Strategy: Mark static
/skills/and/memories/as cache-eligible components in the harness.
B. The 75/25 Rule
Aim to keep 75% of the context window free for “Reasoning Space” (Thinking and Tool Results) and only 25% for “Background Knowledge” (System Prompt and History). Overloading background knowledge leads to “Context Drowning” where the agent stops being creative.
Reference: Expanded based on PromptingGuide.ai Techniques
Reference: Inspired by PromptingGuide.ai Context Engineering