PromptBase
PromptBase SelectGet Select
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
Chat - (gpt-5.6)
Token size
2,779
Example input
[AGENT_ARCHITECTURE_AND_CONTEXT_PIPELINE]: AI coding agent for large software repositories. Pipeline: User task → repository scan → task planner → code search → Git history → tool calls → context builder → LLM. Repository: 2.4M lines of code. Average active context: 48,000 tokens. The agent can access source files, tests, issues, and architecture docs. [SYSTEM_PROMPT_AND_AGENT_INSTRUCTIONS]: Agent must understand the requested change, inspect existing code, follow repository conventions, modify code safely, run tests, explain changes, and avoid unrelated modifications. System prompt: 6,500 tokens. [CONVERSATION_HISTORY_AND_CONTEXT_SAMPLES]: Average session: 12 user/agent turns. History contains previous code explanations, failed approaches, shell outputs, file contents, and completed subtasks. Average history contribution: 9,000 tokens. [MEMORY_ARCHITECTURE_AND_STORED_INFORMATION]: Memory stores repository conventions, previous architectural decisions, user preferences, common commands, and completed task information. Average memory contribution: 3,500 tokens. [QUALITY_REQUIREMENTS_AND_OPTIMIZATION_CONSTRAINTS]: Reduce context tokens by at least 45%. Code-task success must remain at least 99% of baseline. Do not omit files required for dependency reasoning. Reduce median latency by at least 30%. No major model change is allowed.
Example output
🔎 PHASE 1 — CONTEXT ARCHITECTURE RECONSTRUCTION The current context pipeline is: USER TASK ↓ REPOSITORY SCAN ↓ CODE SEARCH ↓ DOCUMENTATION SEARCH ↓ GIT HISTORY ↓ MEMORY ↓ CONVERSATION HISTORY ↓ TOOL OUTPUTS ↓ CONTEXT BUILDER ↓ LLM Approximate average context: Component Tokens System instructions 6,500 Conversation history 9,000 Code/document retrieval 16,000 Memory 3,500 Other agent/tool state ~13,000 Total ~48,000 The largest unknown is agent/tool state because the input does not provide a detailed breakdown. Therefore, the 48K total is measured, while the component allocation containing "~13K" is an estimate. --- 📦 PHASE 2 — CONTEXT COMPONENT PROFILING Component Value Freshness Duplication Classification User task Very high Immediate Very low 🟢 Essential Core instructions Very high Stable Medium 🟢 Essential Relevant source code Very high Current Low 🟢 Essential Relevant tests Very high Current Low 🟢 Essential Relevant Git history Medium-High Historical Medium 🟡 Useful Recent conversation High Recent Medium 🟡 Useful Full conversation Low-Medium Mixed High 🟠 Conditional Repository memory Medium Mixed Medium 🟡 Useful All memory Low-Medium Mixed High 🟠 Conditional All search results Low Mixed High 🔴 Low Value Completed subtasks Low after resolution Stale High 🔴 Low Value The critical insight is that source-code relevance is more important than source-code quantity. --- 🗑️ PHASE 3 — REDUNDANCY & DUPLICATION AUDIT Major duplication risks: 1. Source-code overlap Multiple search results may reference the same functions, classes, or dependency chains. Potential saving: 2,000-4,000 tokens 2. Git-history duplication Fifteen commits may repeatedly describe the same implementation decision. Potential saving: 1,000-2,000 tokens 3. Conversation duplication Previous explanations may repeat information already visible in the current repository. Potential saving: 3,000-5,000 tokens 4. Memory duplication Repository conventions may already exist in system instructions or retrieved documentation. Potential saving: 1,000-2,000 tokens 5. Tool-output duplication Shell output and file contents may contain information already represented in agent state. Potential saving: 2,000-4,000 tokens Estimated total opportunity: 9,000-17,000 tokens. These are estimates, not measured savings. --- 🕒 PHASE 4 — CONVERSATION HISTORY BLOAT ANALYSIS The current 9,000-token history should not be preserved as one block. Divide it into: Keep verbatim Current user request Latest decisions Unresolved questions Current implementation state Recent errors affecting the task Summarize Earlier reasoning Previous implementation attempts Completed subtasks Earlier explanations Discard Repeated explanations Old shell output Superseded approaches Completed unrelated tasks Recommended structure: Current task + Open decisions + Current implementation state + Relevant recent messages + Compact historical summary Target: 9,000 → 3,000-4,000 tokens --- 🎯 PHASE 5 — CONTEXT RELEVANCE & PRIORITIZATION Use a weighted relevance score: Context Score = Task Relevance + Dependency Relevance + Recency + Information Uniqueness + Reliability + Reasoning Value - Token Cost Recommended priority: Tier 1 Current user request Critical instructions Relevant source files Relevant tests Active errors Tier 2 Dependency files Architecture decisions Relevant recent conversation Relevant Git history Tier 3 General repository conventions Supporting documentation Older decisions Tier 4 Unrelated files Completed subtasks Generic explanations Duplicate results --- 🔎 PHASE 6 — RETRIEVAL PRIORITIZATION ARCHITECTURE Current retrieval is too broad: 20 files + 10 documentation chunks + 15 commits Instead use: User Task ↓ Intent + Dependency Extraction ↓ Broad Candidate Retrieval ↓ Code Reranking ↓ Dependency Expansion ↓ Semantic Deduplication ↓ Evidence Compression ↓ Context Budget An important improvement is dependency-aware retrieval. If the target function imports three critical modules, those modules should receive higher priority than unrelated files with similar textual matches. --- 🗜️ PHASE 7 — CONTEXT COMPRESSION STRATEGY Recommended techniques: Technique Savings Quality Risk Recommendation Duplicate removal High Very Low Strongly recommended Structured tool extraction High Low Strongly recommended History summarization Medium-High Medium Recommended Retrieval compression Medium Medium Recommended Hierarchical summaries High Medium Recommended Aggressive source-code summarization High High Avoid by default Important rule Do not aggressively summarize source code. A coding agent often needs exact: Function signatures Conditions Types Imports Error handling Tests Configuration Data structures Therefore source code should primarily be selected, not heavily summarized. --- 🧠 PHASE 8 — MEMORY VS ACTIVE CONTEXT ACTIVE CONTEXT Keep: Current task Relevant files Current errors Relevant tests Current implementation state Immediate dependencies LONG-TERM MEMORY Keep: Stable repository conventions Persistent architectural decisions User's coding preferences Established project conventions EXTERNAL KNOWLEDGE Retrieve: Repository documentation Historical implementation details Framework documentation Old architectural discussions DISCARD Remove: Completed temporary subtasks Old shell logs Obsolete implementation attempts Duplicate repository conventions Promotion Rule Information should move into long-term memory only when it is: stable + reusable + likely to matter again. Temporary task information should not automatically become memory. --- 🧰 PHASE 9 — TOOL & RETRIEVED-CONTENT OPTIMIZATION The agent should stop injecting raw tool responses. Instead: Tool ↓ Parser ↓ Relevant-field extraction ↓ Deduplication ↓ Structured result ↓ Context builder Example: Instead of: Large terminal output produce: TEST RESULT Status: FAILED Failing test: PaymentServiceTest.retryPayment Error: Expected 200, received 500 Relevant file: payment_service.py Likely dependency: retry_handler.py This preserves reasoning-critical information while removing noise. --- 💰 PHASE 10 — TOKEN CONSUMPTION & COST MODELING Measured average input: 48,000 tokens/task Measured peak: 82,000 tokens/task Measured output: 3,200 tokens/task Monthly tasks: 25,000 Monthly input: 25,000 × 48,000 = 1.2 billion tokens Monthly output: 25,000 × 3,200 = 80 million tokens Total: ~1.28 billion tokens/month Exact monetary cost cannot be calculated because model pricing was not supplied. That should explicitly remain an unknown, rather than inventing a price. --- ⚡ PHASE 11 — LATENCY & CONTEXT PERFORMANCE ANALYSIS Current median/average latency: 14 seconds The likely major contributors are: 1. Large context processing 2. Repository search 3. Multiple retrieval operations 4. Large tool outputs 5. Repeated context assembly The highest-value latency optimization is therefore: Reduce unnecessary context before adding additional compression infrastructure. Potential improvement target: 14 seconds → <10 seconds This would represent approximately a 29% reduction and is close to the requested 30% target. Actual improvement must be benchmarked. --- ⚖️ PHASE 12 — QUALITY VS TOKEN-COST TRADE-OFF For a coding agent, context reduction has a unique danger: Removing a seemingly irrelevant dependency can break reasoning. For example: Target file ↓ Imported helper ↓ Configuration ↓ Integration test Removing the helper may save tokens but cause an incorrect implementation. Therefore: Dependency-aware selection > simple token truncation. Recommended stopping condition: Reduce context ↓ Run coding benchmark ↓ Accuracy ≥99% baseline? ↓ YES Reduce further ↓ NO Restore highest-value context --- 📊 PHASE 13 — CONTEXT BUDGET DESIGN Recommended target budget: Context Category Budget System instructions 4,000 Current task 1,000 Recent conversation 2,500 Agent state 3,000 Relevant source code 8,000 Tests 3,000 Retrieval/documentation 3,000 Git history 1,000 Memory 1,000 Target ~26,500 This would reduce average context from: 48K → ~26.5K Approximate reduction: 45% This directly satisfies the minimum optimization target. Overflow rules If context exceeds budget: 1. Remove duplicate retrieval 2. Remove irrelevant documentation 3. Compress old conversation 4. Reduce Git history 5. Reduce non-critical memory 6. Compress tool results 7. Preserve source/test dependency chain 8. Never remove critical instructions --- 🧪 PHASE 14 — OPTIMIZATION EXPERIMENT PLAN Create three groups. Group A — Baseline Current architecture: ~48K tokens Group B — Moderate Optimization Approximately: 30-35K tokens Changes: History compression Retrieval filtering Tool-output structuring Memory filtering Group C — Aggressive Optimization Approximately: 24-27K tokens Changes: Dynamic budgets Dependency-aware retrieval Hierarchical summaries Adaptive context selection Measure: Metric Baseline Target Input tokens 48K ≤26K Task success 100% baseline ≥99% Latency 14s ≤9.8s Failed implementations Baseline No significant increase Test pass rate Baseline ≥99% Unrelated code changes Baseline No increase Use representative coding tasks covering: Bug fixes Feature additions Refactoring Multi-file changes Dependency-heavy changes Test failures Large repositories Ambiguous requirements --- 🛠️ PHASE 15 — CONTEXT OPTIMIZATION ROADMAP 🔥 0-30 DAYS 1. Deduplicate retrieval Expected saving: 2K-4K tokens Quality impact: Very low Effort: Low Risk: Low 2. Compress conversation history Expected saving: 4K-6K tokens Quality impact: Low-Medium Effort: Medium Risk: Medium 3. Structure tool outputs Expected saving: 2K-4K tokens Quality impact: Low Effort: Medium Risk: Low --- 🚀 31-90 DAYS Implement: Dynamic context budgets Dependency-aware code retrieval Semantic deduplication Relevance scoring Conditional memory Hierarchical conversation summaries Expected context reduction: 45-55% --- 🏗️ 3-6 MONTHS Implement: Adaptive context allocation Automatic context-quality scoring Context observability Retrieval evaluation Task-specific context policies Automated regression testing Context optimization based on task type The final system should dynamically decide whether a task requires: Small Context Medium Context Large Context rather than using one fixed context size. --- 🧾 PHASE 16 — FINAL CONTEXT OPTIMIZATION BLUEPRINT Executive Summary The coding agent currently suffers from broad retrieval, oversized history, raw tool outputs, and indiscriminate memory injection. Current average: 48K tokens Target: ~26K tokens Potential reduction: ~45% The highest-risk optimization is aggressive source-code compression. The safest optimization opportunities are: 1. Deduplication 2. Tool-output filtering 3. History compression 4. Conditional memory 5. Dependency-aware retrieval --- 🎯 FINAL RECOMMENDATION The optimized architecture should be: USER TASK ↓ TASK + DEPENDENCY ANALYSIS ↓ CONTEXT REQUIREMENT ESTIMATION ↓ PARALLEL RETRIEVAL ├── Relevant Code ├── Tests ├── Documentation ├── Git History └── Memory ↓ RERANK ↓ DEPENDENCY EXPANSION ↓ DEDUPLICATE ↓ COMPRESS HISTORY + TOOL OUTPUTS ↓ DYNAMIC CONTEXT BUDGET ↓ FINAL VALIDATION ↓ LLM Highest-impact changes 1. Dependency-aware retrieval Prevents the agent from throwing unrelated repository content into context. 2. Dynamic context budgeting Allows simple tasks to use small contexts while complex tasks receive additional context. 3. History condensation Keeps decisions and unresolved state without carrying the entire conversation. 4. Structured tool outputs Converts noisy terminal/API results into compact decision-relevant information. 5. Conditional memory Only injects memory when it has measurable relevance to the current coding task. The goal should not be: > "Make the context as small as possible." The correct goal is: > "Give the coding agent the smallest sufficient context that preserves dependency reasoning and maintains at least 99% of baseline task success." That is the key optimization principle this sample test should verify.
GPT

Agent Context Window Optimizations

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
GPT-5.6
Tested icon
Guide icon
4 examples icon
Free credits icon
Oversized agent context increases token costs and latency while burying important information and degrading response quality. You Get :- 🔍 Analyze every context component 🗑️ Detect redundant information & history bloat 🎯 Prioritize the most valuable context 🧠 Optimize memory vs active context 🗜️ Design compression strategies 💰 Estimate token consumption & cost ⚖️ Balance quality, latency & token usage 📊 Build a practical context budget Turn bloated agent context into a lean, cost-efficie
...more
Added over 1 month ago
Report
Browse Marketplace