arXiv:2610.25550cs.AIOct 2026

Manuscript Offprint

arXiv:2610.25550

Editing as Language: Teaching LLM Agents a Grammar for Native Context Editing

Yunlong Deng, Yan Li, Xing Hu, Yida Zhu, Sean Du, Weiyang Liu, Guangyi Chen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

A synopsis in novels folds a story into a few lines; a function in code gathers many steps with a single execution. Context editing is native to language itself. In this paper, we propose the Native Context Editing (NCE) framework, which gives language model agents a grammar for natively editing their own context. By encoding context-editing operations in a grammar of dedicated special tokens, we teach the agents to invoke edits through the language itself. We train agents on iteratively constructed trajectory segments, with each teacher edit conditioned on the evolving context. This establishes context editing as an atomic and inherent capability of LLM agents, enabling them to dynamically modify their context as they generate responses over long-horizon reasoning and interaction. Compared with context-editing methods that learn to generate tool-use code within specific external harness environments, our approach integrates context editing as an internal mechanism of the model's native generation process, enabling better generalization across diverse real-world workflows. On four long-horizon agentic benchmarks (Terminal-Bench 2.0, SWE-bench Verified, SWE-bench Multilingual, and SWE-bench Pro), NCE improves the average task success rate over the base model by 5.6 percentage points for LongCat-Flash-Lite-Sparse and by 4.5 for Qwen3.6-35B-A3B, while reducing average token usage by 36% and 15%, respectively.

1 Introduction

Large language model (LLM) agents now tackle tasks that require many rounds of reasoning, tool use, and interaction with environments (Yang et al., 2024; Wang et al., 2025, 2026). In these long-horizon tasks, the interactions accumulate code, tool outputs, execution feedback, and intermediate decisions into increasingly long histories (Lindenbauer et al., 2025). Long-horizon agents therefore need to maintain useful working context within a finite window: retain evidence for upcoming decisions, shorten completed investigations, and remove information that is no longer needed.

Existing approaches manage context through either predefined rules or external tools. Even the most widely deployed coding agents rely on rules. Claude Code and Codex summarize the history once it crosses a fixed token threshold (Anthropic, 2025; OpenAI, 2025), and simpler policies mask older observations (Lindenbauer et al., 2025). These triggers fire on context size alone and cannot tell which information the task still needs. Tool-based methods expose context management through external tool calls, letting the agent decide what to edit. Sculptor provides tools to fragment, summarize, hide, and restore the history (Li et al., 2026), and Context-Folding folds a finished sub-trajectory into a summary (Sun et al., 2025). Because the harness defines and executes these tools, the learned editing policy is bound to harness-specific interfaces and generalizes poorly across different environments.

Both families define context editing outside the model. Rules fix the policy in the harness, and tools, even when a learned policy calls them, take their meaning from schemas that the harness declares in the prompt. We therefore seek to answer:

How can we turn context editing into a native capability of language models?

We call context editing native when each edit takes its meaning from the model’s own vocabulary, as the end-of-sequence token <eos> does. No

∗^{*}Equal contribution. †^{\dagger}Corresponding authors.

Correspondence to 1155281107@link.cuhk.edu.hk

(Y. Deng), wyliu@cse.cuhk.edu.hk (W. Liu), and

guangyichen1994@gmail.com (G. Chen). Y. Deng's work

was done during an internship at Meituan.

Figure

(a) Agent edits its context in the language it generates

Figure

(b) Task success vs. token usage

Figure 1: Overview of NCE. (a) The agent writes edits inline with its output, each naming a target block by its icon: drop removes a file it no longer needs, rewrite condenses a failing test log to one line; the runtime applies them before the agent continues. (b) Success vs. tokens per task for LongCat-Flash-Lite-Sparse (69B-A3B) on Terminal-Bench 2.0 (Table 2). NCE succeeds most with the fewest tokens at every budget.

prompt needs to explain <eos>, and it ends generation the same way in every harness. Our answer is to make editing part of the language the model speaks. Language already provides natural primitives for organizing information, e.g., a summary compresses a story into a few lines, a function name abstracts a sequence of operations, and an updated note supersedes outdated information. Guided by this intuition, we introduce Native Context Editing (NCE), a framework that equips LLM agents with an executable grammar to compress, abstract, update, and restructure their own context as reasoning unfolds (Figure 1a).

Specifically, NCE organizes the context into addressable blocks, and its grammar has three components: a vocabulary of dedicated tokens, in which address tokens name blocks and operator tokens (drop, rewrite, append) remove, replace, or add them; composition rules that define well-formed edits; and semantics that bind each well-formed edit to exactly one transition of the context state, executed by a task-agnostic runtime. The meaning of every edit thus ships with the model and holds in every harness. Recorded trajectories contain no edits, so we annotate them with two teachers. An offline teacher reads the full trajectory and assigns each block a release point, the turn after which the block may be edited. A block is released only when the teacher can cite the event that ended its use. An online teacher then uses the previous blocks and release annotations from the offline teacher to decide when and how to edit. The edits are thus safe to learn and executable by an agent that cannot see ahead.

We then train NCE through distillation over these editing trajectories, with supervision that follows the context as it is edited. Specifically, each edit is executed at the end of the turn that issues it, and every later editing decision and task action is constructed and supervised on the resulting context. Annotating all edits on the original history would condition later decisions on text that the agent has already deleted or rewritten, a mismatch that grows with every edit. By executing each edit before the next turn is built, NCE trains the agent on contexts shaped by its earlier edits. This is exactly the condition it faces at inference time, therefore bridging the train-test gap. During inference, the model generates each turn, the runtime executes the edits it contains, and generation resumes from the edited context, so the context can evolve throughout long-horizon reasoning.

In the experiments, we have implemented NCE on LongCat-Flash-Lite-Sparse (69B-A3B) and Qwen3.6-35B-A3B and evaluated both on four long-horizon agentic benchmarks, including Terminal-Bench 2.0 (Merrill et al., 2026), SWE-bench Verified (Jimenez et al., 2024), SWE-bench Multilingual (Yang et al., 2025b), and SWE-bench Pro (Deng et al., 2025). On LongCat at 256K, NCE improves success over the base model by 4.8 to 6.3 points and reduces token usage by 31% to 44% on every benchmark (Table 1 and Figure 1b). A tool-call editing baseline trained on the same edits trails NCE by 5.2 to 8.0 points, so the gap comes from expressing the edits natively. The gains transfer to Qwen3.6, where NCE raises the average success rate over the base model by 4.5 points and cuts average token usage by 15%.

We summarize our contributions below:

• We introduce Native Context Editing (NCE), a framework that teaches LLM agents a grammar to dynamically manage their own active context through natively generated edits.

• We develop a distillation framework with evolving contexts, where an offline teacher uses release analysis in hindsight to decide which blocks to edit, and an online teacher that sees only the present makes the edits.

• We evaluate NCE on four long-horizon agentic benchmarks, demonstrating its effectiveness in improving task performance while also reducing both context and token usage over the base model with harness compaction.

References (20)