Elamur Research⌕
☰
home / papers / 2026 / CodeMEM: AST-Guided Adaptive Memory for Repository-Level Iterative Code Generation

CodeMEM: AST-Guided Adaptive Memory for Repository-Level Iterative Code Generation

Paper · 2026 · Peiding Wang, Li Zhang, Fang Liu et al.

Summary

When developers work with an LLM over several turns inside a code repository, two things tend to go wrong. The relevant repository context drifts as requirements change. The growing dialogue history also makes the model forget earlier fixes or bring back bugs that were already solved. Existing memory systems such as MemGPT or Mem0 store history as plain natural language, so they lose code structure. CodeMEM replaces this with a code-aware memory built from Python AST analysis, in two parts:

  • Code Context Memory splits the repository into function and class blocks. An LLM decides when this context needs refreshing, and an AST-based Selector keeps only blocks whose APIs connect to the newly generated code.
  • Code Session Memory records each code unit together with its edits and later feedback. An AST-based diff Detector flags likely forgetting, and the LLM is then prompted to resolve it.

On CodeIF-Bench and a multi-turn extension of CoderEval, CodeMEM beats memory-based and full-context baselines while keeping latency and token use competitive. This shows that structure-aware memory makes iterative coding assistants more reliable.

Key points

  • Current-turn instruction following rises 12.2%, and session-level instruction following rises 11.5%. Sessions need roughly 2–3 fewer interaction rounds.
  • Baselines include BM25, RLCoder, Mem0, A-Mem, MemGPT and full-context prompting. Forgetting is measured with the IFR metric, where CodeMEM's advantage grows in later rounds.
  • Repository blocks are stored as key–value pairs: signatures, attributes and method names form the key, and the full implementation is the value. The LLM sees only keys when deciding on updates, which keeps prompts short.
  • Context management adds about 2.8 s per round on CodeIF-Bench and 4.0 s on CoderEval. Removing the AST Selector roughly doubles token consumption on CodeIF-Bench.
  • Code and data are available at github.com/zhu-zhu-ding/CodeMem. The authors note the method has not yet been tested on industrial-scale repositories or longer dialogues.

Our summary of the paper, in our own words — not its text. The work belongs to its authors; read it at the links above.

 Institutions

 Fields, topics and concepts

Cite

Cite as Peiding Wang, Li Zhang, Fang Liu, Chongyang Tao and Yinghao Zhu. 2026. CodeMEM: AST-Guided Adaptive Memory for Repository-Level Iterative Code Generation. Findings of the Association for Computational Linguistics: ACL 2026.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2026.findings-acl.834

@inproceedings{wang2026codemem,
  title = {{CodeMEM: AST-Guided Adaptive Memory for Repository-Level Iterative Code Generation}},
  author = {Peiding Wang, Li Zhang, Fang Liu, Chongyang Tao and Yinghao Zhu},
  booktitle = {Findings of the Association for Computational Linguistics: ACL 2026},
  year = {2026},
  doi = {10.18653/v1/2026.findings-acl.834},
  url = {https://doi.org/10.18653/v1/2026.findings-acl.834}
}

References

28 references, 11 of them with a card of ours. ↗ leads to the work, «find» searches for one we have no id for yet.

  1. Anonymous. 2025. Memagent: Reshaping long-context LLM with multi-conv RL-based memory agent. In Submitted to The Fourteenth International Conference on Learning Representations. Under review. find
  2. Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie Cai, Michael Terry, Quoc Le, and 1 others. 2021. Program synthesis with large language models. arXiv preprint arXiv:2108.07732.
  3. Ge Bai, Jie Liu, Xingyuan Bu, Yancheng He, Jiaheng Liu, Zhanhui Zhou, Zhuoran Lin, Wenbo Su, Tiezheng Ge, Bo Zheng, and Wanli Ouyang. 2024. MT-bench-101: A fine-grained benchmark for evaluating large language models in multi-turn dialogues. In Proceedings of the 62nd Annual Meeting of the Associatio…
  4. Egor Bogomolov, Aleksandra Eliseeva, Timur Galimzyanov, Evgeniy Glukhov, Anton Shapkin, Maria Tigina, Yaroslav Golubev, Alexander Kovrigin, Arie van Deursen, Maliheh Izadi, and Timofey Bryksin. 2024. Long code arena: a set of benchmarks for long-context code models. Preprint, arXiv:2406.11612. — [arXiv:2406.11612](https://arxiv.org/abs/2406.11612) find
  5. Mark Chen. 2021. Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374.
  6. Prateek Chhikara, Dev Khant, Saket Aryan, Taranjeet Singh, and Deshraj Yadav. 2025. Mem0: Building production-ready ai agents with scalable long-term memory. Preprint, arXiv:2504.19413.
  7. Yun He, Di Jin, Chaoqi Wang, Chloe Bi, Karishma Mandyam, Hejia Zhang, Chen Zhu, Ning Li, Tengyu Xu, Hongjiang Lv, and 1 others. 2024. Multi-if: Benchmarking llms on multi-turn and multilingual instructions following. arXiv preprint arXiv:2410.15553. — [arXiv:2410.15553](https://arxiv.org/abs/2410.15553) find
  8. Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Keming Lu, Kai Dang, Yang Fan, Yichang Zhang, An Yang, Rui Men, Fei Huang, Bo Zheng, Yibo Miao, Shanghaoran Quan, and 5 others. 2024. Qwen2.5-coder technical report. Preprint, arXiv:2409.12186.
  9. Naman Jain, King Han, Alex Gu, Wen-Ding Li, Fanjia Yan, Tianjun Zhang, Sida Wang, Armando Solar-Lezama, Koushik Sen, and Ion Stoica. 2025. Livecodebench: Holistic and contamination free evaluation of large language models for code. In The Thirteenth International Conference on Learning Representatio…
  10. Philippe Laban, Hiroaki Hayashi, Yingbo Zhou, and Jennifer Neville. 2025. Llms get lost in multi-turn conversation. Preprint, arXiv:2505.06120.
  11. Jia Li, Ge Li, Xuanming Zhang, Yihong Dong, and Zhi Jin. 2024a. Evocodebench: An evolving code generation benchmark aligned with real-world code repositories. Preprint, arXiv:2404.00599. — [arXiv:2404.00599](https://arxiv.org/abs/2404.00599) find
  12. Jia Li, Ge Li, Yunfei Zhao, Yongmin Li, Huanyu Liu, Hao Zhu, Lecheng Wang, Kaibo Liu, Zheng Fang, Lanshen Wang, Jiazheng Ding, Xuanming Zhang, Yuqi Zhu, Yihong Dong, Zhi Jin, Binhua Li, Fei Huang, Yongbin Li, Bin Gu, and Mengfei Yang. 2024b. DevEval: A manually-annotated code generation benchmark al… find
  13. Zhiyu Li, Shichao Song, Hanyu Wang, Simin Niu, Ding Chen, Jiawei Yang, Chenyang Xi, Huayi Lai, Jihao Zhao, Yezhaohui Wang, Junpeng Ren, Zehao Lin, Jiahao Huo, Tianyi Chen, Kai Chen, Kehang Li, Zhiqiang Yin, Qingchen Yu, Bo Tang, and 3 others. 2025. Memos: An operating system for memory-augmented gen… — [arXiv:2505.22101](https://arxiv.org/abs/2505.22101) find
  14. Wei Liu, Ailun Yu, Daoguang Zan, Bo Shen, Wei Zhang, Haiyan Zhao, Zhi Jin, and Qianxiang Wang. 2024. Graphcoder: Enhancing repository-level code completion via coarse-to-fine retrieval based on code context graph. In Proceedings of the 39th IEEE/ACM International Conference on Automated Software Eng… find
  15. Charles Packer, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica, and Joseph E. Gonzalez. 2024. Memgpt: Towards llms as operating systems. Preprint, arXiv:2310.08560. find
  16. Peiding Wang, Li Zhang, Fang Liu, Lin Shi, Minxiao Li, Bo Shen, and An Fu. 2025a. Codeif-bench: Evaluating instruction-following capabilities of large language models in interactive code generation. Preprint, arXiv:2503.22688. — [arXiv:2503.22688](https://arxiv.org/abs/2503.22688) find
  17. Peiding Wang, Li Zhang, Fang Liu, Yinghao Zhu, Wang Xu, Lin Shi, Xiaoli Lian, Minxiao Li, Bo Shen, and An Fu. 2025b. Efficientedit: Accelerating code editing via edit-oriented speculative decoding. Preprint, arXiv:2506.02780. — [arXiv:2506.02780](https://arxiv.org/abs/2506.02780) find
  18. Xingyao Wang, Zihan Wang, Jiateng Liu, Yangyi Chen, Lifan Yuan, Hao Peng, and Heng Ji. 2024. Mint: Evaluating llms in multi-turn interaction with tools and language feedback. Preprint, arXiv:2309.10691.
  19. Yanlin Wang, Yanli Wang, Daya Guo, Jiachi Chen, Ruikai Zhang, Yuchi Ma, and Zibin Zheng. 2025c. RLCoder: Reinforcement Learning for Repository-Level Code Completion, page 1140–1152. IEEE Press. find
  20. Di Wu, Wasi Uddin Ahmad, Dejiao Zhang, Murali Krishna Ramanathan, and Xiaofei Ma. 2024. Repoformer: Selective retrieval for repository-level code completion. Preprint, arXiv:2403.10059. — [arXiv:2403.10059](https://arxiv.org/abs/2403.10059) find
  21. Wujiang Xu, Zujie Liang, Kai Mei, Hang Gao, Juntao Tan, and Yongfeng Zhang. 2025. A-mem: Agentic memory for llm agents. Preprint, arXiv:2502.12110.
  22. Hao Yu, Bo Shen, Dezhi Ran, Jiaxin Zhang, Qi Zhang, Yuchi Ma, Guangtai Liang, Ying Li, Qianxiang Wang, and Tao Xie. 2024. Codereval: A benchmark of pragmatic code generation with generative pre-trained models. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, ICSE… find
  23. Zexun Zhan, Shuzheng Gao, Ruida Hu, and Cuiyun Gao. 2025. Sr-eval: Evaluating llms on code generation under stepwise requirement refinement. Preprint, arXiv:2509.18808. — [arXiv:2509.18808](https://arxiv.org/abs/2509.18808) find
  24. Fengji Zhang, Bei Chen, Yue Zhang, Jacky Keung, Jin Liu, Daoguang Zan, Yi Mao, Jian-Guang Lou, and Weizhu Chen. 2023. RepoCoder: Repository-level code completion through iterative retrieval and generation. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pag… find
  25. Kechi Zhang, Jia Li, Ge Li, Xianjie Shi, and Zhi Jin. 2024. CodeAgent: Enhancing code generation with tool-integrated agent systems for real-world repo-level coding challenges. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1…
  26. Qianhui Zhao, Li Zhang, Fang Liu, Xiaoli Lian, Qiaoyuanhe Meng, Ziqian Jiao, Zetong Zhou, Jia Li, and Lin Shi. 2025. Fastcoder: Accelerating repository-level code generation via efficient retrieval and verification. Preprint, arXiv:2502.17139. — [arXiv:2502.17139](https://arxiv.org/abs/2502.17139) find
  27. Wanjun Zhong, Lianghong Guo, Qiqi Gao, and Yanlin Wang. 2023. Memorybank: Enhancing large language models with long-term memory. arXiv preprint arXiv:2305.10250. find
  28. Qihao Zhu, Daya Guo, Zhihong Shao, Dejian Yang, Peiyi Wang, Runxin Xu, Y Wu, Yukun Li, Huazuo Gao, Shirong Ma, and 1 others. 2024. Deepseek-coder-v2: Breaking the barrier of closed-source models in code intelligence. arXiv preprint arXiv:2406.11931. *Table 4: Results of Qwen2.5-Coder-32B-Instruct an…

Updated

↑ back to top

This page in Markdown → https://md.research.elamur.ai/free/en/papers/wang-2026-codemem-ast-guided-adaptive-memory/