← 返回 2026-04-16

记忆迁移学习:编码智能体中跨领域记忆如何迁移 Memory Transfer Learning: How Memories are Transferred Across Domains in Coding Agents

Kangsan Kim, Minki Kang, Taeil Kim, Yanlai Yang, Mengye Ren, Sung Ju Hwang 📅 2026-04-15 👍 30 2026-07-13 08:36
检索增强生成 编码智能体 自进化智能体 记忆迁移学习 迁移学习

首次系统研究编码智能体在不同领域间迁移记忆的机制与规律,证明抽象的元知识是最有效的迁移载体,平均提升 3.7% 性能。

前置知识

基于记忆的自进化智能体 (Memory-based Self-Evolving Agents)

一类 LLM 智能体范式,它把过去的推理执行轨迹(命令、观察、奖励)存为'记忆',在后续任务中检索并复用其中的成功模式、失败教训或抽象洞察,从而在测试时无需再训练就能持续提升能力。代表性工作如 ReasoningBank、AgentKB、MemEvolve 等。

本论文的核心研究对象正是这类系统;理解它们的'记忆生成—检索—复用'闭环机制,是看懂本文做异构记忆池统一化、以及讨论四种记忆格式抽象度差异的前提。

迁移学习与非参数知识迁移 (Transfer Learning & Non-parametric Knowledge Transfer)

传统迁移学习利用参数化适配(fine-tune、adapter)将源域知识迁移到目标域;而非参数化迁移(如 in-context learning、agent 自身的 memory)则不改模型权重,仅在推理时通过上下文/记忆传递知识。本文研究的 MTL 属于后者——通过检索异构记忆实现跨域知识迁移。

本文借鉴传统迁移学习'源域—目标域'框架来分析编码任务间的迁移,并提出'抽象度—可迁移性'命题,这是连接迁移学习经典理论与现代智能体记忆系统的桥梁。

嵌入检索与相似度匹配 (Embedding-based Retrieval)

用文本嵌入模型(如 text-embedding-3-small)把任务和记忆都映射到向量空间,通过 cosine similarity 选出 top-N 最相关的记忆注入到系统 prompt。论文中所有检索都基于这种范式,并对比了 LLM 重排序、自适应改写等高级方法。

理解检索管线是看懂全文实验设计的基础——Table 7 的对比实验就揭示了简单嵌入检索在异构设置下反而优于复杂方法,这是论文的核心反直觉发现之一。

代码智能体与执行环境 (Coding Agents & Execution Environment)

基于 LLM 的、通过 bash、文件读写、调试等工具与代码仓库交互以完成任务的系统(如 mini-swe-agent、OpenHands)。它们共享 Linux shell、Python/R/C++ 运行时、跨文件依赖栈等底层基础设施,而这些共通层正是跨领域记忆可以被有效迁移的前提。

论文之所以能跨领域迁移,前提就是不同编码任务(竞赛编程、仓库级工程、ML 复现)共用同一执行栈;不了解这点就难以理解为什么 SWE-Bench 和 MLGym-Bench 的记忆可以互相帮助。

Pass@k 评测指标 (Pass@1 / Pass@3)

在编码任务中,让模型对每个问题采样 k 次(可用不同温度),只要有一次通过单元测试即视为成功。Pass@k 通常取多轮平均。论文主表用 Pass@3,附录 Table 8 给 Pass@1 数值。

懂 Pass@k 才知道论文里 0.910→0.940 看似小数点的差异在统计上稳健可信,这也是为什么每条结论都用三跑平均来报告。

研究动机

现有基于记忆的自进化编码智能体(如 ReasoningBank、AgentKB、MemEvolve)几乎都把记忆的产生和检索严格限制在同一领域、同一基准内——比如 SWE-Bench 上构建的记忆只用来解下一道 SWE 题。然而真实编码场景的领域跨度极大:函数级竞赛编程(LiveCodeBench、Aider Polyglot)、仓库级工程修复(SWE-Bench Verified、Terminal-Bench2)、科学论文代码复现(ReplicationBench)、ML 研究任务(MLGym-Bench)。这些任务虽然表面上很不一样,但底层共享 Linux shell、Python/C++ 运行时、依赖管理等基础设施。论文指出:当前方法'有意无意'地把记忆池'围栏化'在单一基准里,造成三大浪费——(1) 跨领域元知识(如安全写盘、最小补丁、断言验证)无法被新任务复用;(2) 即使 AgentKB 这种'跨任务'方案也只是塞入 5899 条噪声记忆却没做机制分析;(3) 检索到的低层命令级轨迹(Trajectory)经常把任务特定代码细节强加给风格/环境都不同的目标任务,反而引发负迁移。

本文的目标是本文的核心目标是对'编码智能体中的跨域记忆迁移学习'(Memory Transfer Learning, MTL)做第一次系统性、机制层面的实证研究,把异构领域中产生的记忆统一汇入一个共享记忆池,并在 6 个差异极大的编码基准上量化迁移效果,最终回答三大研究问题:RQ1 异构记忆能否提升编码智能体性能;RQ2 为什么迁移过来的记忆有用;RQ3 哪些因素决定迁移有效度。作者并不只是给一个 SOTA,而是想要建立一套'什么时候用、用什么格式、怎么检索'的设计原则。

与已有工作不同的是,切入角度的独特性有两层:第一,把研究从'记忆库越大越好'转向'记忆池的领域构成和抽象度构成',用 DBI/LISI、t-SNE、命题 1 形式化模型给出量化结论;第二,本文是第一个系统拆解'高层洞察(Insight)vs 低层轨迹(Trajectory)'在跨域时表现差异的工作,并通过嵌入式聚类证明 Insight 嵌入几乎失去任务聚类结构——这比之前工作(如 AgentKB 简单堆记忆、ReasoningBank 只用同域 97 条记忆)都更精细。

核心方法

方法直觉很朴素:与其让每个基准各自维护一份记忆,不如把所有基准上跑出来的成功/失败轨迹都送进一个共享池,提取成四种抽象度递增的记忆格式(Trajectory→Workflow→Summary→Insight),离线索引好。在线推理时根据目标任务的嵌入相似度取出 top-3(也可以是 LLM 重排序或重写)注入系统 prompt。技术上设计为两阶段——离线'记忆生成'和在线'记忆检索'。生成阶段用 gpt-5-mini 当 LLM judge 判定每条轨迹成功/失败,再用专门 prompt 产出对应格式的记忆;检索阶段对每个 query 任务取出 top-3 嵌入最相似的记忆。整个评估在 6 个基准 × 3 个底座模型(GPT-5-mini/DeepSeek V3.2/Qwen3-Coder-480B)上进行,并引入领域排除(leave-one-benchmark-out)的记忆池构造,保证没有数据泄露。

核心创新在于把'记忆抽象度'作为一个独立可控的变量进行端到端实验,而不是把它当成一个固定超参。具体说,本文的 MTL 让跨领域记忆可以'跨任务边界'流动的同时,量化了'越抽象越能迁移'的规律:Insight 这种 title-description-content 三段式、且在 prompt 里就显式禁止提及具体文件名的高层知识,比照搬原命令的 Trajectory 在 6 个基准上平均高出 6 个百分点(0.560 vs 0.534),且在最容易负迁移的 MLGym-Bench(零样本 0.667→Trajectory 0.583 退化;Insight 反过来升到 0.750)上差异最显著。这与已有 AgentKB'量取胜'和 ReasoningBank'域内取胜'思路形成鲜明对比。

方法步骤详情

完整 pipeline 包括:(1) 全基准推理——先用 mini-swe-agent 在 6 个基准上跑一遍收集完整轨迹 H=(t, [(r₁,a₁,o₁),...(rₙ,aₙ,oₙ)]);(2) 成功/失败判定——用 LLM judge 区分轨迹,如果成功就把整段轨迹当成原料,失败也保留以提取反例;(3) 四格式记忆生成——Trajectory 直接拼 (a,o) 对;Workflow 用 prompt 抽'goal+可复用动作序列';Summary 生成'任务摘要+经验段';Insight 生成 (title, description, content) 三段且 content 必须 task-agnostic;(4) 异构记忆池构造——对目标基准 Bᵢ,记忆池 P_τ(Bᵢ) = {M_τ^(k) | t^(k) ∉ Bᵢ},即包含除本基准外所有来源任务的同格式记忆;(5) 嵌入索引——用 text-embedding-3-small 把每条记忆的 task 信息(Trajectory)或计划(Workflow/Summary/Insight)编码成向量存库;(6) 在线检索——对当前 query 任务生成嵌入(Trajectory 用任务嵌入;其余三种用 LLM 写 4-5 句任务计划再嵌入),取 cosine top-3 注入 mini-swe-agent 的系统 prompt;(7) 评测——同 Benchmark 跑三遍报告 Pass@3。

技术新颖性

技术新颖性主要体现在三方面:(a) 抽象度作为显式自变量——论文不是设计一种新记忆格式,而是把现有四种格式排在一个抽象度光谱上系统比较,并通过'将同一格式按 task-specific 度再切两半'进一步剥离'格式 vs 抽象度'两个变量,得出即使 Insight 内部 task-agnostic 子集也比 task-specific 子集高 1.1%;(b) 异构记忆池的 leave-one-out 构造——比 AgentKB 那种扁平堆叠更严谨,避免数据泄露;(c) 形式化建模——附录 C 把每条记忆嵌入分解为 z_inv(域不变元知识)+z_sp(领域特定),定义抽象度 A=∥z_inv∥²/(∥z_inv∥²+∥z_sp∥²),并证明命题 1:在嵌入范数有界假设下,期望迁移收益随 A 严格递增。这把工程经验转化成了可证伪的理论。

Illustrative examples of four memory formats. We utilize Trajectory, Workflow, Summary, and Insight formats to analyze how different levels of information abstraction affect cross-task transferability.
Figure 2: Illustrative examples of four memory formats. We utilize Trajectory, Workflow, Summary, and Insight formats to analyze how different levels of information abstraction affect cross-task transferability.
t-SNE Visualization of Memory Formats. The leftmost plot shows task embeddings, followed by three different memory types to the right.
Figure 4: t-SNE Visualization of Memory Formats. The leftmost plot shows task embeddings, followed by three different memory types to the right.
Embedding Distribution Analysis DBI and LISI reveal weaker separation and stronger mixing with higher abstraction.
Figure 5: Embedding Distribution Analysis DBI and LISI reveal weaker separation and stronger mixing with higher abstraction.

实验结果

在 6 个基准 × 3 模型 = 主表 1 的系统评测中,MTL 用 Insight 时在 GPT-5-mini 上平均比 zero-shot 提升 3.7%(从 0.523 到 0.560),其中 MLGym-Bench 升 8.3%(0.667→0.750)、ReplicationBench 升 7.8%(0.111→0.189)、Terminal-Bench2 升 4.5%、SWE-Bench Verified 升 4.0%,但 LiveCodeBench v6 和 Aider-Polyglot 上几乎持平。迁移有效性随抽象度梯度递增——Insight(0.560) > Summary(0.546) > Workflow(0.538) > Trajectory(0.534),且在最容易出现负迁移的 MLGym-Bench 上 Insight 反向把 Trajectory 的'反向坑'(0.583 < 0.667 退化 12.6%)逆转成正收益,说明抽象度比格式本身更重要。Table 2 的自进化基线对比更说服力:MTL 仅用 431 条记忆,平均 0.630 超过 AgentKB(5899 条记忆、0.613)和 ReasoningBank(97 条记忆、0.601)分别 +1.7% 和 +2.9%。Figure 6 的池规模/领域数消融显示,把记忆池从 1/4 扩到 Full(或从 2 个域扩到 9 个域)时平均分单调上升。Table 6 的跨模型迁移说明:GPT-5-mini 生成的记忆喂给 DeepSeek V3.2 仍能比 zero-shot 高 +1.5%,反向也行,证明被迁移的是模型无关的元知识。Table 4 把 Insight 内部按'可否反推原任务'切成任务特定 vs 任务无关两组,任务无关组仍稳定胜出(平均 0.534 vs 0.523),进一步剥离'格式'的混杂因素。Figure 3 把贡献拆成 10 类(迭代工作流纪律 15.0%、探索策略 14.5%、测试驱动验证 14.4%、交互协议 10.4%、API 合规 8.5%、环境适配 8.1%、文件语法 7.8%、反模式回避 9.5%、输入校验 5.5%、算法策略 5.5%),可见元过程类贡献合计 ~80%,而直接的算法策略只占 5.5%,有力支持'MTL 迁移的是元知识不是算法本身'的核心论断。

Evaluation results of Memory Transfer Learning. We report Pass@3 scores across multiple benchmarks. MTL consistently improves performance over the zero-shot baseline across models. Among memory types, Insight achieves the highest average performance.
Table 1: Evaluation results of Memory Transfer Learning. We report Pass@3 scores across multiple benchmarks. MTL consistently improves performance over the zero-shot baseline across models. Among memory types, Insight achieves the highest average performance.
Pass@3 comparison with self-evolving methods. LCB, SWEB, and RepliB denote LiveCodeBenchv6, SWEBench-Verified, and ReplicationBench, respectively.
Table 2: Pass@3 comparison with self-evolving methods. LCB, SWEB, and RepliB denote LiveCodeBenchv6, SWEBench-Verified, and ReplicationBench, respectively.
Case Study: Zero-shot vs. Memory Transfer Learning with Insight. Transferred Insight from LiveCodeBench to SWE-Bench Verified provides meta-knowledge regarding strategic guidance (e.g., inline test validation), allowing the agent to succeed where the zero-shot baseline fails.
Table 3: Case Study: Zero-shot vs. Memory Transfer Learning with Insight. Transferred Insight from LiveCodeBench to SWE-Bench Verified provides meta-knowledge regarding strategic guidance (e.g., inline test validation), allowing the agent to succeed where the zero-shot baseline fails.
Memory Abstraction Effect. Task-agnostic insights outperform task-specific ones, highlighting abstraction as a key driver.
Table 4: Memory Abstraction Effect. Task-agnostic insights outperform task-specific ones, highlighting abstraction as a key driver.
Case Study: Memory Transfer Learning with Trajectory vs. Insight. Trajectory memory transferred from MLGym-Bench illustrates that blindly following low-abstraction memory leads to execution errors due to task-specific command. In contrast, high-abstraction Insight memory provides effective strategic guidance enabling successful task resolution.
Table 5: Case Study: Memory Transfer Learning with Trajectory vs. Insight. Trajectory memory transferred from MLGym-Bench illustrates that blindly following low-abstraction memory leads to execution errors due to task-specific command. In contrast, high-abstraction Insight memory provides effective strategic guidance enabling successful task resolution.
Cross-Model Memory Transfer. Average Pass@1 results show consistent gains over zero-shot across different model pairs.
Table 6: Cross-Model Memory Transfer. Average Pass@1 results show consistent gains over zero-shot across different model pairs.
Retrieval Method Comparison. Pass@3 results show that simple embedding-based retrieval outperforms advanced methods.
Table 7: Retrieval Method Comparison. Pass@3 results show that simple embedding-based retrieval outperforms advanced methods.
Evaluation results of Memory Transfer Learning (Appendix A) — Average Pass@1 Results across the three base models and six benchmarks for ZeroShot and four MTL variants.
Table 8: Evaluation results of Memory Transfer Learning (Appendix A) — Average Pass@1 Results across the three base models and six benchmarks for ZeroShot and four MTL variants.
Negative Transfer Cases (Appendix B). Below examples illustrate failures in Memory Transfer Learning due to the misapplication or distortion of retrieved knowledge.
Table 9: Negative Transfer Cases (Appendix B). Below examples illustrate failures in Memory Transfer Learning due to the misapplication or distortion of retrieved knowledge.
Breakdown of Memory Transfer Contribution. Transferred memory mainly contributes through meta-knowledge.
Figure 3: Breakdown of Memory Transfer Contribution. Transferred memory mainly contributes through meta-knowledge.
Memory Scaling. Larger memory pools and more domains lead to better performance through increased diversity.
Figure 6: Memory Scaling. Larger memory pools and more domains lead to better performance through increased diversity.
查看结构化数据
任务指标本文基线提升
LiveCodeBench v6 (函数级竞赛编程) Pass@3 MTL(Insight) = 0.930 Zero-shot = 0.910 +2.0%
Aider-Polyglot (函数级多语言编程) Pass@3 MTL(Insight) = 0.470 Zero-shot = 0.470 0.0%(无增益,函数级任务本身已接近上限)
SWE-Bench Verified (仓库级真实 GitHub Issue) Pass@3 MTL(Insight) = 0.770 Zero-shot = 0.730 +4.0%
Terminal-Bench2 (命令行长链路任务) Pass@3 MTL(Insight) = 0.360 Zero-shot = 0.315 +4.5%
ReplicationBench (科学论文代码复现) Pass@3 MTL(Insight) = 0.189 Zero-shot = 0.111 +7.8%(绝对提升最显著基准之一)
MLGym-Bench (ML 研究任务代理) Pass@3 MTL(Insight) = 0.750 Zero-shot = 0.667 +8.3%(单基准最大提升)
对比自进化方法(AgentKB / ReasoningBank) Pass@3 平均(LCB+SWEB+RepliB) MTL = 0.630(431 条记忆) AgentKB = 0.613(5899 条)/ ReasoningBank = 0.601(97 条) vs AgentKB +1.7%、vs ReasoningBank +2.9%
DeepSeek V3.2 跨模型兼容性 Pass@3 平均 MTL(I) = 0.568 Zero-shot = 0.542 +2.6%
Qwen3-Coder 跨模型兼容性 Pass@3 平均 MTL(I) = 0.501 Zero-shot = 0.483 +1.8%
抽象度隔离实验(同 Insight 内 task-agnostic vs task-specific) Pass@3 平均 Task-agnostic Insights = 0.534 Task-specific Insights = 0.523 +1.1%(证明抽象度本身是迁移驱动因素)

局限与改进

作者承认的局限主要有两点:(1) 当某些基准(如 LiveCodeBench v6、Aider-Polyglot)在零样本上已经接近上限(如 0.91、0.47 的天花板效应)时,MTL 的增益空间被压扁,方法优势难以体现;(2) Table 7 揭示在异构设置里先进的检索方法(LLM 重排、自适应改写)反而不如简单嵌入检索,说明静态检索设计无法应对智能体在多步推理中的动态需要——这是开放问题。我自己额外观察三点:(a) 主表 Pass@3 但附录 Pass@1 也有规模类似改善但绝对值明显更低,说明单样本下 MTL 优势仍然有效;(b) LiveCodeBench 上 Trajectory 反而得到最高 Pass@3 (0.940),与 Insight 几乎打平,提示在高度函数化、极少环境交互的任务上低层细节也能用;(c) 跨模型迁移虽然有效但始终小幅低于自生成记忆(附录 Table 6 GPT5 记忆用在 GPT5 上 0.543 vs 用于其他模型最多 0.528),说明模型特定偏差仍存在,论文没深挖;(d) 所有实验都基于 gpt-5-mini 一个 LLM judge 去标注成功/失败,存在 judge 偏差传导到记忆质量的风险。

独立分析的弱点

独立分析几个值得改进的弱点:(1) 检索管线静态——目前 top-3 是在任务最开始一次性注入的,但论文 Table 5/Table 9 的案例都展示出'步骤级误导'(如在第 N 步才发现匹配错环境),未来可引入 step-wise dynamic retrieval,根据当前执行上下文实时更新;(2) 负迁移检测缺失——AgentKB 那种堆叠 5899 条记忆时显然噪声很多,但 MTL 没有内置检测/降权机制,应该引入打分或拒答模块,自适应决定是否使用某条记忆;(3) 评测覆盖偏差——6 个基准里只有 SWE-Bench Verified 和 Terminal-Bench2 是真正仓库级长链路,MLGym/ReplicationBench 又有各自领域特殊性,未来应加入 multi-turn editing、cross-file refactor、CI-failure fix 等更日常的工程场景;(4) 记忆编码依赖 LLM judge,对小模型不友好——如果部署到 Qwen3-Coder 这种本地部署场景,昂贵 gpt-5-mini 调用就是瓶颈;(5) 缺乏理论保证——附录 C 命题 1 假设嵌入'范数有界',但真实 embedding 模型不一定满足,且没用真实数据验证该命题是否与实际迁移收益相关。改进方向可考虑:用 ReMe 的 memory refinement 做动态改写;引入 self-consistency 判断拒绝有害记忆;构建 benchmark-of-memory-quality 评测集;用蒸馏把 gpt-5-mini 的 judge 换成 7B 本地模型。

未来方向

作者在 Conclusion 给出的延伸方向包括:(1) 把 MTL 从编码智能体推广到通用 agentic memory;(2) 研究更鲁棒的检索/适配模块,避免负迁移;(3) 探索系统级记忆演化框架(与 MemEvolve 结合)。基于成果还可延伸:(a) 把元知识聚类为'通用 SOP 库'(验证流、错误恢复、最小补丁、安全文件操作 4 类),做成可即插即用的元模式工具集;(b) 引入 persona-conditioned memory——让同一类记忆对不同抽象度的目标智能体(如规划强 vs 编码强)选择性呈现;(c) 与 self-rewarding / RLVR 结合,让检索成功率作为反馈训练记忆优选器;(d) 把 MTL 与 web agent、GUI agent 记忆池做成统一跨模态 memory bus,研究'领域迁移性'在文本/视觉/代码三栖上的统一度量;(e) 探索 memory-to-memory distillation,让一个智能体的高速记忆通过教师-学生压缩到另一模型中。

复现评估

复现评估:作者在 https://memorytransfer.github.io/ 提供主页,但正文及 README 范围内未明确给出代码仓地址(论文未声明正式开源仓库)。实验依赖方面:(1) 模型——gpt-5-mini、DeepSeek V3.2、Qwen3-Coder-480B-A35B-Instruct 均为公开 API/权重;(2) 框架——mini-swe-agent 作为 coding agent、harbor 作为评测平台、text-embedding-3-small 作为嵌入模型,这三者都是 github 开源;(3) 数据——6 个基准(LiveCodeBench v6、Aider Polyglot、SWE-Bench Verified、Terminal-Bench2、ReplicationBench、MLGym-Bench)均公开可下;(4) 算力——每个基准 100 个 sample,三跑平均,总任务量 6×100×3=1800 次推理 × 加上记忆生成约 4 倍轨迹 ≈ 7200 次 LLM 调用,按 GPT-5-mini 价计约数十美元量级,可见中小实验室就能复现;(5) 实现难度——prompt 模板(Appendix E 完整给出)可逐字复现;memory pool 构造、leave-one-out 切分、DBI/LISI 评估指标都是标准做法。整体复现门槛中等偏低,主要风险在于 LLM judge 可能因 API 升级而出现判定不一致。