Editing as Language: Teaching LLM Agents a Grammar for Native Context Editing
Organizations: The Chinese University of Hong Kong · Meituan LongCat Team · Nanyang Technological University · Mohamed bin Zayed University of Artificial Intelligence ·
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.
Figures & tables
| LongCat-Flash-Lite-Sparse (69B-A3B) | Qwen3.6-35B-A3B | |||||||||
| Success (%) | Tokens ( ) | Success (%) | Tokens ( ) | |||||||
| Benchmark | rules | tools | native | rules | tools | native | rules | native | rules | native |
| Comp. | Tools | NCE | Comp. | Tools | NCE | Comp. | NCE | Comp. | NCE | |
| TB 2.0 | 32.6 | 32.6 | 38.2 +5.6 | 6.62 | 6.38 | 4.60 31% | 38.2 | 43.8 +5.6 | 2.98 | 3.04 +2% |
| SWE Verified | 65.2 | 62.4 | 70.0 +4.8 | 4.07 | 3.40 | 2.70 34% | 69.8 | 74.0 +4.2 | 2.92 | 2.19 25% |
| SWE Multiling. | 56.0 | 54.3 | 62.3 +6.3 | 10.83 | 10.93 | 6.12 44% | 58.0 | 64.3 +6.3 | 5.12 | 4.13 19% |
| Success (%) | Tokens ( ) | |||||
|---|---|---|---|---|---|---|
| Budget | Comp. | Tools | NCE | Comp. | Tools | NCE |
| 256K | 32.6 | 32.6 | 38.2 +5.6 | 6.62 | 6.38 | 4.60 31% |
| 128K | 25.8 | 30.3 | 34.8 +4.5 | 6.08 | 4.96 | 3.70 39% |
| 64K | 27.0 | 29.2 | 32.6 +3.4 | 3.42 | 3.58 | 2.52 26% |
| 48K | 20.2 | 27.0 | 30.3 +3.3 | 3.40 | 3.17 | 2.15 37% |
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
| Statistic | Value |
|---|---|
| Segments per trajectory | 2.9 |
| Decision points per trajectory | 2.0 |
| milestone / soft / hard | 60 / 38 / 2% |
| Segments without edits | 31% |
| Edited blocks: rewrite / drop | 35 / 65% |
| Appended notes, share of operations | 2% |
| Context (K) | |||||||
|---|---|---|---|---|---|---|---|
| Method | Solved | Success (%) | Tokens (M) | Mean | Peak | Reductions | Turns |
| Harness compaction | 23 | 25.8 | 6.08 | 38.3 | 79.7 | 0.6 | 119 |
| Sliding window | 23 | 25.8 | 4.62 | 43.6 | 71.5 | 1.7 | 92 |
| Fixed memory state | 26 | 29.2 | 5.59 | 44.0 | 72.9 | 1.9 | 95 |
| Prompt compression | 29 | 32.6 | 4.68 | 38.3 | 66.0 | 14.0 | 95 |
| NCE | 31 | 34.8 | 3.70 | 30.5 | 61.1 | 3.1 | 99 |
| Trajectories (%) | One pass | Original | NCE |
|---|---|---|---|
| Uses future information | 30.0 | 12.5 | 5.0 |
| Deletes evidence used later | 72.5 | 40.0 | 37.5 |
| Edits a removed block | 0.0 | 95.0 | 0.0 |
| Restates removed text | 7.5 | 85.0 | 2.5 |
| Any defect | 80.0 | 100.0 | 37.5 |
| Defective edits (%) | 4.5 | 22.5 | 1.1 |
| Prefill rate | Terminus-2 | Claude Code |
|---|---|---|
| 5K tokens/s | 92 | 62 |
| 9.5K tokens/s | 98 | 81 |
| 20K tokens/s | 100 | 93 |
| 40K tokens/s | 100 | 98 |
| Time hidden (9.5K) | 98 | 81 |
LLM Context Management
Large language model context management studies how to select, compress, retrieve, and organize information within bounded model inputs.
See all 251 papers