Cluster-Aware Dynamic Context Engineering for High-Diversity Task Trajectories
Cluster failed execution trajectories by semantic error type to construct localized mini-playbooks that are dynamically retrieved during inference, preventing context pollution on diverse tasks.
Time
Compute level
Resources
What the paper used
Prerequisites
Scope
The Gap
Section 5 and Figure 5 demonstrate a strong negative correlation (r = -0.5, p <= 0.05) between failure mode diversity (Vendi score) and performance gains across LCE methods. Current consolidation steps (e.g. global prompt rewriting in GEPA or global bullet pools in ACE) attempt to merge highly heterogeneous error types into a single system context, which fails to distill shared principles and degrades on diverse tasks like AppWorld.
“Extracted experiences show no consistent reduction in diversity over training iterations, suggesting that current LCEs struggle to distill shared principles.”
Limitation
Current LCE consolidation mechanisms try to fit all failure patterns into a single static context, causing catastrophic interference and dilution when task trajectories present heterogeneous failure modes.
Proposed Solution
Implement a two-stage context engineering pipeline. First, run trajectory failure extraction and embed diagnoses using sentence transformers. Perform unsupervised clustering (e.g., HDBSCAN) on the failure embeddings to discover distinct error subclasses. Second, optimize separate contextual guidance units (mini-playbooks) per cluster rather than one global prompt. At test time, use a lightweight classifier or semantic retrieval to dynamically select and inject only the relevant cluster playbook based on query context.
The paper’s authors list this direction as future work, so they may already be pursuing it.
Why This Matters
Enabling LCEs to handle diverse failure modes could unlock training-free prompt optimization for complex, multi-faceted domains like long-horizon agentic workflows and mixed reasoning benchmarks.
How to Get Started
How to test it: Evaluate cluster-aware dynamic context retrieval against baseline ACE and TF-GRPO on high-diversity benchmarks (AppWorld and HotpotQA) using Qwen3-8B. Metric: test set task success rate (pass@1). Stop project if dynamic cluster retrieval fails to beat global ACE by at least 3 percentage points.
- Clone the paper's released benchmark codebase at https://github.com/costa-nus/LCEBench.
- Extract initial rollout failure trajectories on AppWorld using Qwen3-8B and generate sentence embeddings using all-mpnet-base-v2.
- Implement HDBSCAN clustering on failure embeddings to verify distinct cluster separation.
- Modify the ACE playbook consolidation step to maintain cluster-indexed sub-playbooks and retrieve them based on test prompt cosine similarity.
Code linked to this paper on Hugging Face: github.com/costa-nus/LCEBench
Suggested by AI. Adapt it to your setup.
Has This Been Done?
None of the provided papers implement unsupervised clustering on failure embeddings to dynamically select cluster-specific playbooks for context engineering. While papers like ExpertRAG and OmniLLP discuss context retrieval and optimization, they do not address failure-subclass clustering for dynamic guidance.
We searched OpenAlex and arXiv for “dynamic prompt optimization dynamic context retrieval failure mode clustering LLM context engineering” and “Cluster-Aware Dynamic Context Engineering for High-Diversity Task Trajectories” and an AI compared the idea with the top 10 results. A small search can miss relevant work.
Source Paper
Revisiting LLMs as Context EngineersJunrui Zhang, Zeyu Xu, Runchuan Zhu +7 more · 2026
This paper presents a systematic benchmark evaluating Large Language Model as Context Engineer (LCE) approaches across diverse reasoning tasks and open-weight model families. The authors find that existing LCE methods do not consistently outperform standard Chain-of-Thought or In-Context Learning baselines, and their effectiveness is bottlenecked by model inability to distill unified principles from highly diverse failure modes.
Related Ideas
- Dynamic Multi-Step Retrieval for Long-Horizon TasksRemember Me, Refine Me: A Dynamic Procedural Memory Framework for Experience-Driven Agent Evolution🟠Medium
- Utility-Tracked Consolidation and Failure-Aware Retrieval for Harness Improvement LibrariesHarness^2: Recursive Agent Harnessing for an Open World🟡Fairly easy
- Dynamic Context Summarization for Long-Running TasksAutoDev: Automated AI-Driven Development🟡Fairly easy
- Automated Cross-Modal Trajectory Auditing for Silent Environment and Scoring DefectsGame2Player: Scaling Gameplay Experience for Visual Agents through Environment-Player Co-Development🟡Fairly easy
- Hierarchical Retrieval-Augmented Self-Improvement Memory for Extended Optimization HorizonsSelf-Improvement Memory Enables Continual Recursive Self-Improvement🟡Fairly easy