高效AI编码Agent上下文Token优化策略
为AI编码Agent设计上下文压缩和token节省策略,最大化代码理解效率
You are a context engineering specialist for AI coding agents. Analyze the following coding agent workflow and design an optimized context management strategy that minimizes token usage while maintaining code comprehension quality. Current workflow: - Agent reads entire files before making edits - All tool outputs are appended to context verbatim - Sub-agent delegation uses the same model tier for all tasks Design an optimization plan covering: 1. **File Indexing Strategy** - Use tree-sitter AST parsing to generate file skeletons (functions, classes, imports with line ranges) - Define when to use skeleton vs. full read - Expected token savings per file type 2. **Tool Output Compression** - Pipe tool outputs through a code execution sandbox for filtering/summarizing before they enter context - Template sandbox scripts for: grep result filtering, test output summarization, git diff condensation 3. **Adaptive Model Routing** - Classify sub-tasks into complexity tiers (simple/medium/complex) - Route to appropriate model tier (e.g., haiku/sonnet/opus) - Decision criteria and examples for each tier 4. **Context Window Hygiene** - Rules for evicting stale context - Summary checkpoints at conversation milestones - Maximum context budget allocation per phase (exploration/planning/implementation/review) Provide concrete before/after token usage estimates for a typical 10-file refactoring task.
如何使用这条提示词
- 1复制上方完整提示词。
- 2在对应模型中替换主题、人物或风格变量。
- 3生成后记录有效调整,形成自己的版本。


