返回提示词库
文本 · 通用大模型AI编码Agent上下文窗口沙箱化与输出压缩策略PW
创作者Prompt2 编辑部PromptWhisper 收录
文本通用大模型开发与工程

AI编码Agent上下文窗口沙箱化与输出压缩策略

针对编码Agent的上下文窗口优化策略,通过沙箱化工具输出实现98%的token压缩率。适用于Claude Code、Codex、Cursor等AI编程工具的效率优化。

13浏览
完整提示词可替换花括号中的变量后直接使用

You are a Context Window Optimization Engineer for AI coding agents. Your goal is to help me implement strategies that dramatically reduce token consumption while preserving the information density needed for effective code generation. ## Problem Statement Coding agents waste 60-90% of their context window on verbose tool outputs (file listings, test results, build logs, LSP diagnostics). This limits their ability to handle complex, multi-file tasks. ## Optimization Framework ### 1. Output Sandboxing Strategy Design a sandboxing layer that: - Intercepts tool call results before they enter the context - Extracts only decision-relevant information - Stores full output in retrievable side-channels - Provides compressed summaries with retrieval pointers ``` [Tool Output: 2000 tokens] -> [Sandbox Filter] -> [Summary: 50 tokens + pointer] ``` ### 2. Compression Techniques by Tool Type | Tool Type | Raw Output | Compressed Form | Technique | |-----------|-----------|----------------|----------| | File listing | Full tree | Changed files + relevant dirs | Delta filtering | | Test results | Full stdout | Failed tests + error lines | Pass/fail extraction | | Build logs | Entire log | Errors + warnings only | Severity filtering | | Git diff | Full patch | Summary + key hunks | Semantic compression | | LSP diagnostics | All issues | Relevant to current task | Scope filtering | ### 3. Implementation Patterns For each tool in my agent's toolkit, provide: ```yaml tool: <tool_name> raw_output_avg_tokens: N compressed_output_avg_tokens: M compression_ratio: X% filter_rules: - include: <what to keep> - exclude: <what to drop> - summarize: <what to condense> retrieval_strategy: <how to get full output if needed> ``` ### 4. Context Budget Allocation Given a context window of [N] tokens, recommend allocation: - System prompt: X% - Conversation history: Y% - Current task context: Z% - Tool outputs (sandboxed): W% - Reserve for generation: R% ### 5. Adaptive Compression - When context is <50% full: light compression - When context is 50-80% full: moderate compression - When context is >80% full: aggressive compression + eviction ## Deliverables 1. A compression middleware implementation (Python/TypeScript) 2. Configuration file for common coding tools 3. Metrics dashboard design for monitoring compression effectiveness 4. A/B test design to validate quality preservation ## My Setup - Agent platform: [Claude Code / Codex / Cursor / Custom] - Primary languages: [list] - Typical task complexity: [simple fixes / feature development / large refactors] - Context window size: [tokens]

2026/5/9

如何使用这条提示词

  1. 1复制上方完整提示词。
  2. 2在对应模型中替换主题、人物或风格变量。
  3. 3生成后记录有效调整,形成自己的版本。