[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-84518-en":3,"doc-seo-84518-105":29,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":13,"seo_description":14,"update_tm":27,"read_time":28},84518,962075006959,"Anda","https://ap-avatar.wpscdn.com/avatar/e0002397efbe92a78e?_k=1776741047341049297",8,"Research & Report","Self-Compacting Language Model Agents","Long agent traces that include chain-of-thought and tool calls can accumulate stale, misleading content and eventually exceed the context window. Existing approaches rely on fixed-interval compaction triggers, which ignore the trajectory’s reasoning state and can discard partial results mid-derivation or mid-search. SELFCOMPACT introduces adaptive compaction where the model decides when and how to compact using both a summarization tool and a lightweight rubric. No fine-tuning or external supervision is required, and experiments on seven models across multiple benchmarks show lower token cost and improved accuracy.","arXiv :2606 .23525v2 [ cs .CL] 10 Jul 2026  \nSelf-Compacting Language Model Agents  \nTianjian Li♠ Jingyu Zhang♠ William Jurayj♠ Xi Wang♠ Chuanyang Jin♠ Mehrdad Farajtabar♡ Eric Nalisnick♠ Daniel Khashabi♠  \n♠Johns Hopkins University ♡Apple  \n{tli104, [danielk}@jhu.edu](danielk}@jhu.edu)  \nAbstract  \nLong agent traces composed of chains of thought and tool calls accumulate stale content that anchor subsequent generations, and eventually outgrow the context window. Existing scaffolds mitigate it with fixed-interval compaction triggered at a token threshold. Such triggers pay no heed to trajectory structure, risking discard of partial results mid-derivation or mid-search. We propose SELFCOMPACT, a scaffold that allows the model itself to decide when and how to compact. Specifically, it pairs two inference-time elements: (i) a compaction tool the model invokes to summarize the accumulated context, and (ii) a lightweight rubric specifying when to fire (a sub-task has resolved, or the trajectory is converging) and when to suppress (mid-derivation, or when stuck) . Both are needed. The tool alone is unevenly used across open-weight models, often invoked at unhelpful moments or not at all; the rubric alone cannot act. Together, they elicit effective adaptive compaction without any fine-tuning or external supervision. We present empirical results on six benchmarks (competitive math and agentic search) and seven models.  \nOur results show that SELFCOMPACT matches or exceeds fixed-interval summarization at a fraction of the token cost, improving over a no-summarization baseline by up to 18.1 points on math and 5–9 points on agentic search at 30–70% lower per-question cost. Our results expose a meta-cognitive gap: although unprompted models cannot reliably tell when their own context is rotting, a lightweight rubric closes this gap, reframing when to compact as a capability that scaffolds can supply without training 1.  \n1 Introduction  \nWe are chasing after harder problems over longer horizons [METR, 2026], and consequently, the trajectories LMs generate to solve them keep growing. Reasoning models are now able to spend tens of thousands of tokens deliberating on a single competition math question: Qwen3.5 produces 81k tokens [Qwen Team, 2026], Kimi-K2.5 produces 96k [Kimi Team et al., 2026] . Agentic systems extend further, orchestrating search results [Wei et al., 2025], code execution outputs [Jimenez et al., 2024], and intermediate plans [Novikov et al., 2025] across hundreds of turns. The bet that more thinking and interactions yields better answers has paid off, but long traces carry a hidden cost. As the trace grows, it accumulates junk—a flawed case split made early, a search result the model has moved past, a candidate program that led nowhere. These leftovers do not just sit there; they anchor everything that follows [Laban et al., 2026] . A model that solves a problem from a clean start often fails when fed back its own flawed reasoning. This phenomenon is known as context rot [Hong et al., 2025, Cheng et al., 2026] . Existing systems try to manage it with rigid rules: compacting the trajectory when a token threshold is met [Cursor Research et al., 2026], or delegating the burden of identifying context rot to the user via /compact [Anthropic, 2025] .  \n1 Code is available at [https://github.com/tianjianl/selfcompact](https://github.com/tianjianl/selfcompact).  \nPreprint. Under Review.  \nFigure 1: Comparison of trajectory-compression strategies on a hard BrowseComp question. The gold answer requires verifying four facts (Agaricus, Bon 1983, Clash 1981, Harryhausen) before composing Medusa mushroom. Baseline (no compression) burns its budget on an unproductive monologue and emits no answer. Fixed-interval compression fires every two search trajectories regardless of reasoning state; the poorly-timed summary wipes verified facts mid-reasoning, leaving the model to guess (Morel Mushroom) . SELFCOMPACT (Ours) gates compression on a","cbCaitVNhde7ByMe","https://ap.wps.com/l/cbCaitVNhde7ByMe","pdf",851119,1,25,"English","en",105,"# Abstract\n# Introduction","[{\"question\":\"What problem does SELFCOMPACT address in long language model agent runs?\",\"answer\":\"It addresses context rot, where stale chain-of-thought and tool-call content accumulates over long trajectories and anchors later generations, hurting final answers.\"},{\"question\":\"Why do fixed-interval compaction methods fail?\",\"answer\":\"Because compaction is triggered purely by token thresholds, it cannot tell whether the model is mid-derivation, mid-search, or has already resolved a sub-task, leading to discard of either stale content or needed partial results.\"},{\"question\":\"How does SELFCOMPACT decide when to compact without training?\",\"answer\":\"SELFCOMPACT combines an inline compaction tool the model invokes with a lightweight rubric that specifies when to fire (e.g., sub-task resolved or trajectory converging) and when to suppress (mid-derivation or when stuck).\"}]",1784196264,63,{"code":4,"msg":30,"data":31},"ok",{"site_id":24,"language":23,"slug":32,"title":13,"keywords":33,"description":14,"schema_data":34,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":27},"self-compacting-language-model-agents","",{"@graph":35,"@context":85},[36,53,68],{"@type":37,"itemListElement":38},"BreadcrumbList",[39,43,47,50],{"item":40,"name":41,"@type":42,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":44,"name":45,"@type":42,"position":46},"https://docshare.wps.com/document/","Document",2,{"item":48,"name":12,"@type":42,"position":49},"https://docshare.wps.com/document/research-report/",3,{"item":51,"name":13,"@type":42,"position":52},"https://docshare.wps.com/document/self-compacting-language-model-agents/84518/",4,{"url":51,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":23,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":40,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-17","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"What problem does SELFCOMPACT address in long language model agent runs?","Question",{"text":75,"@type":76},"It addresses context rot, where stale chain-of-thought and tool-call content accumulates over long trajectories and anchors later generations, hurting final answers.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"Why do fixed-interval compaction methods fail?",{"text":80,"@type":76},"Because compaction is triggered purely by token thresholds, it cannot tell whether the model is mid-derivation, mid-search, or has already resolved a sub-task, leading to discard of either stale content or needed partial results.",{"name":82,"@type":73,"acceptedAnswer":83},"How does SELFCOMPACT decide when to compact without training?",{"text":84,"@type":76},"SELFCOMPACT combines an inline compaction tool the model invokes with a lightweight rubric that specifies when to fire (e.g., sub-task resolved or trajectory converging) and when to suppress (mid-derivation or when stuck).","https://schema.org",{"og:url":51,"og:type":87,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":89,"canonical":51},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":92},[93,97,101,105,110,115,120,123,128,131,135],{"id":20,"doc_module":4,"doc_module_name":45,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":46,"doc_module":4,"doc_module_name":45,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":52,"doc_module":4,"doc_module_name":45,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":45,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":111,"doc_module":4,"doc_module_name":45,"category_name":112,"show_sort_weight":113,"slug":114},6,"Technology",50,"technology",{"id":116,"doc_module":4,"doc_module_name":45,"category_name":117,"show_sort_weight":118,"slug":119},7,"Healthcare",40,"healthcare",{"id":11,"doc_module":4,"doc_module_name":45,"category_name":12,"show_sort_weight":121,"slug":122},30,"research-report",{"id":124,"doc_module":4,"doc_module_name":45,"category_name":125,"show_sort_weight":126,"slug":127},9,"Religion & Spirituality",20,"religion-spirituality",{"id":126,"doc_module":4,"doc_module_name":45,"category_name":129,"show_sort_weight":126,"slug":130},"World Cup","world-cup",{"id":132,"doc_module":4,"doc_module_name":45,"category_name":133,"show_sort_weight":132,"slug":134},10,"Lifestyle","lifestyle",{"id":136,"doc_module":4,"doc_module_name":45,"category_name":137,"show_sort_weight":106,"slug":138},19,"General","general"]