CoReMem: Cost-Internalizing Memory for Successive Coding Tasks with Prospective Valuation
Organizations: Yale University · Tsinghua University · Goodvision AI
Abstract
Coding agents tackle successive tasks on an evolving repository, carrying forward edits and writing memory before the next task is known. Selecting memory for unknown next tasks requires balancing future usefulness against the costs of writing and reading it. The actor must also decide when acting on available memory saves effort as the task unfolds. We introduce Coding-Repository Memory (CoReMem), a cost-internalizing framework that guides memory design and actor adaptation through measured memory value on the next task. Prospective segment valuation compares runs of the next task with and without individual trajectory segments from the same inherited repository state, guiding a compact memory built around anchors: repository locations and executable checks. Actor adaptation estimates on-policy memory value within rollout groups with and without memory, using a reward that prioritizes resolution and penalizes step count in successful runs. Provenance-gated value credit assigns the additional value term to steps identified as using memory-supplied anchors, while every step retains outcome credit. On ChainSWE, CoReMem raises the 27B actor's resolve rate from 21.0% to 25.7%, with 17% fewer steps and 11% fewer total cache-aware tokens, including memory-module calls, relative to the untrained actor model without memory.
Figures & tables
| Memory layer | Linked | Unlinked | Overall | Tokens per session (K) | Res. per K tokens | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. (%) | Steps | Res. (%) | Steps | Res. (%) | Steps | Actor | Writer | Total | Actor | Total | |
| Qwen3.5-9B | |||||||||||
| No memory | 9.7 | 98.4 (91.1) | 19.4 | 98.1 (91.2) | 14.0 | 98.2 (91.2) | 98.3 (98.9) | – | 98.3 (98.9) | 0.152 | 0.152 |
| Full history | 11.4 | 70.0 (60.5) | 17.9 | 76.4 (68.5) | 14.2 +2% | 72.8 (65.1) −26% | 85.9 (79.9) | – | 85.9 (79.9) −13% | 0.156 | 0.156 +3% |
| Mem0 | 12.2 | 94.3 (86.0) | 21.8 | 93.1 (85.2) | 16.4 +17% | 93.8 (86.0) −5% | 96.5 (94.8) | 14.9 (14.4) | 111.4 (109.1) +13% | 0.175 | 0.151 0% |
| MemOp | 11.9 | 93.5 (85.8) | 19.0 | 96.8 (86.3) | 15.0 +7% | 94.9 (86.1) −3% | 99.3 (96.4) | 32.4 (33.1) | 131.7 (131.4) +34% | 0.147 | 0.111 −27% |
| Memory layer | Anchors per 1K chars | Used anchors per memory | Used anchors per 1K chars |
|---|---|---|---|
| Mem0 | 9.7 [9.4, 10.1] | 0.15 [0.09, 0.21] | 0.14 [0.08, 0.21] |
| MemOp | 14.4 [13.6, 15.2] | 2.06 [1.59, 2.51] | 0.92 [0.72, 1.11] |
| ReasoningBank | 8.5 [7.8, 9.1] | 0.65 [0.51, 0.80] | 0.19 [0.14, 0.24] |
| CoReMem w/o training | 15.8 [15.0, 16.7] | 2.24 [1.67, 2.87] | 1.32 [1.00, 1.68] |
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Memory layer | Outcome | Tokens per session (K) | Res. per K tokens | List price | |||||
| Res. (%) | Steps | Actor | Writer | Total | Actor | Total | USD | Res. per USD | |
| Claude Opus 5.5 | |||||||||
| No memory | 38.5 | 12.6 (12.0) | 21.5 (15.7) | – | 21.5 (15.7) | 1.791 | 1.791 | 0.2370 | 162 |
| Full history | 40.6 +5% | 10.4 (9.0) −17% | 27.0 (23.5) | – | 27.0 (23.5) +25% | 1.505 | 1.505 −16% | 0.2384 +1% | 170 +5% |
| Mem0 | 39.6 +3% | 13.0 (12.0) +3% | 18.7 (16.2) | 16.6 (17.8) | 35.4 (34.8) +64% | 2.112 | 1.119 −37% | 0.2893 +22% | 137 −16% |
| MemOp | 39.6 +3% | 17.8 (12.5) +41% | 21.7 (16.0) | 14.4 (12.1) | 36.1 (28.2) +68% | 1.821 | 1.096 −39% | 0.3630 +53% | 109 −33% |
| Actor | Checkpoint | Resolve (%) | Steps mean (med.) | Actor tok (K) mean (med.) | Raw tok (K) | Limit hit (%) | Res/Tok (actor) |
|---|---|---|---|---|---|---|---|
| Qwen3.8-27B-FP8 ( Qwen Team, 2026b ) | untrained | 69.2 1.9 | 28.3 0.2 (21.2) | 24.7 0.6 (17.4) | 383.0 15.2 | 7.0 0.4 | 2.80 0.10 |
| post-trained | 73.7 0.6 +7%** | 26.2 0.3 −7%** (20.5) | 22.5 0.2 −9%** (17.2) | 313.7 1.5 −18%** | 2.5 0.1 −64%** | 3.27 0.05 +17%** | |
| Qwen3.5-9B ( Qwen Team, 2026a ) | untrained | 49.1 2.2 | 90.1 1.3 (86.2) | 93.5 0.4 (86.3) | 2471.9 20.6 | 7.1 1.9 | 0.53 0.03 |
| post-trained | 55.5 0.3 +13%** | 69.9 1.4 −22%** (63.8) | 72.9 1.3 −22%** (64.1) | 1586.1 70.4 −36%** | 0.1 0.1 −99%** | 0.76 0.02 +43%** |
| Memory layer | Linked | Unlinked | Overall | Tokens per session (K) | Res. per K tokens | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Res. (%) | Steps | Res. (%) | Steps | Res. (%) | Steps | Actor | Writer | Total | Actor | Total | |
| Qwen3.8-27B-FP8, agent without network access ( replays) | |||||||||||
| No memory | 31.6 | 59.2 (61.2) | 19.6 | 44.6 (37.5) | 28.1 | 54.9 (54.4) | 89.4 (60.8) | – | 89.4 (60.8) | 0.340 | 0.340 |
| No memory, post-trained actor | 33.8 | 51.2 (48.0) | 21.4 | 39.9 (34.4) | 30.2 +7% | 47.9 (44.8) −13% | 76.2 (47.8) | – | 76.2 (47.8) −15% | 0.406 | 0.406 +19% |
| CoReMem w/o training | 36.8 | 40.3 (36.4) | 19.6 | 43.2 (39.1) | 31.8 +13% | 41.2 (39.1) −25% | 61.5 (41.4) | 5.2 (2.0) | 66.7 (43.4) −25% | 0.561 | 0.517 +52% |
| CoReMem | 40.4 | 35.7 (32.0) | 16.1 | 34.8 (29.9) | 33.3 +19% | 35.4 (30.4) −35% | 57.6 (35.1) | 4.0 (1.9) | 61.6 (37.2) −31% | 0.628 | 0.583 +71% |
| Memory layer | Resolve (%) | Steps | Tokens (K) | Resolve per M tokens |
|---|---|---|---|---|
| No memory | 10.6 | 33.8 | 897 | 11.9 |
| Full history | 14.9 | 41.8 | 1704 | 8.8 |
| Mem0 | 11.2 | 38.3 | 1176 | 9.5 |
| MemOp | 14.4 | 38.5 | 1273 | 11.9 |
| ReasoningBank | 21.8 | 48.0 | 1943 | 11.3 |
| CoReMem w/o training | 16.5 | 38.6 | 1240 | 13.3 |
| Segment | What it holds | In the example session (Figure 9 ) |
|---|---|---|
| Reasoning text | The actor’s own text in each step, outside the command | “Now let me verify the fix works with a test script.” (step 8) |
| Commands | Every command the actor ran, in order, with the shell exit code of its step ( for success, nonzero for failure) | python -m pytest tests/ -k "sim102" -q [exit 0] (step 9); a grep on a file that does not exist [exit 2] (step 2) |
| Repository content | Output of commands that read or search the repository, and of any other command that is not a test | The file list of flake8_simplify/rules/ and the two lines of ast_if.py that mention SIM102 (step 3); the flake8 warning on the negative case (step 8) |
| Test output | Output of test runners, of scripts written in the session and of inline Python with an assert | 4 passed, 88 deselected (step 9); 90 passed, 2 xfailed (step 10) |
| Change | The diff the task left in the tree, and output of commands that print a diff | added lines in ast_if.py that define is_main_check and call it (step 11) |
| Outcome | How the session ended, its exit status and step count | Submitted after steps |
| Segment | Measurement on linked boundaries | Decision | Line of the memory |
|---|---|---|---|
| C1 reasoning | Deleting it costs no step (34 helped, 45 hurt) and saves 1.14K tokens ( ) | Step 3 kept a reason field; Step 4 dropped it | None; the instruction forbids reasons and summaries |
| C2 commands | Deleting it costs a median 2 steps (56/27, BH ); alone it carries the whole saving; the failing commands alone carry half | Kept; failed checks stay in it with their exit code | VERIFY exact command [exit ] | COVERS paths |
| C3 repository content | Deleting it costs a median step (52/34, BH ) and saves 0.63K tokens | Kept as located facts | CONTEXT fact | WHERE path:lines, in the repository block |
| C4 test feedback | Test commands with exit codes beat the full test output by a median step (53/30, BH ) | A test result is the exit code of its command | TESTS last full test command [last exit ]; no pasted output |
| C5 change | Deleting the diff body costs no step (47/44) and saves 0.94K tokens ( ); the file list matches the full diff ( ) | Anchors only, body banned | DID one clause | WHERE path:lines (symbols); the change is committed and is not restated |
| C6 outcome | No effect overall (45/33); helps when the current task resolved (24/11) | Observable part kept, hidden-test verdict banned; Step 4 places it in the task block | STATUS submitted, stopped or no change, inside the task block |
| Kind | Role | Rule | Example |
|---|---|---|---|
| File path | location | has a / and a letter, or a code extension | flake8_simplify/ rules/ast_if.py |
| Symbol | location | snake, camel, dotted or hyphenated, not all common words | is_main_check , ast.Constant |
| Test node id | check | contains :: , its path and name also count | tests/test_x.py:: test_y |
| Command token | check | non-flag token inside a command or a VERIFY / TESTS field | flake8 , sim102 |
Agent Memory
Agent memory lets AI systems retain, update, and use facts, experiences, and skills across sessions and long-horizon tasks.
See all 208 papers