Agent memory · Harness engineering

Agent 是怎么记住事情的How an Agent Remembersエージェントはどう記憶するのか

用户说“按上次的格式来”,Agent 要完成三件事:找到上次的格式,把它放进这次的输入,再据此行动。沿着这条路径看,记忆机制就容易理解了。When a user says ‘use the same format as last time,’ an agent has three jobs: find that format, bring it into the current input, and act on it. Following this path makes agent memory easier to understand.ユーザーが「前回と同じ形式で」と言ったとき、エージェントには三つの仕事があります。前回の形式を見つけ、今回の入力に入れ、それに従って動くこと。この経路をたどると、記憶の仕組みが見えてきます。

2026 年 10 月 · 实现解读October 2026 · Implementation notes2026年10月 · 実装を読み解く

以 SWALM 的 MainAgent 为例,沿着一条信息的保存与读取路径,看看它怎样在需要时被模型看见。Following how SWALM’s MainAgent stores and retrieves a fact shows how that information reaches the model when needed.SWALMのMainAgentを例に、情報の保存と読み出しをたどり、必要なときにどうモデルへ届くかを見ていきます。

先分清三个地方Three places information can live情報が置かれる三つの場所

当前输入像工作台,放着模型这次能看到的内容;记忆库和文件像资料柜,需要取用;原始轨迹像流水账,记录发生过什么。资料柜里有记录,流水账里有原话,都不代表下一次模型调用已经看到了它。The current input is a workbench: it holds what the model can see now. Memory stores and files are a filing cabinet: their contents need to be fetched. The raw trace is a ledger of what happened. A fact in the cabinet or ledger does not automatically appear in the next model call.現在の入力は作業台です。今回モデルが見られる内容が載っています。記憶ストアやファイルは取り出して使う資料棚、元の軌跡は出来事を記録する台帳です。棚や台帳に情報があっても、次のモデル呼び出しで見えているとは限りません。

系统规则、用户请求和近期对话进入当前输入。偏好可以按预算自动注入;过去的任务和日记通过 memory recall 搜索,经验与 Skills 通过 Read 读取。取回的内容进入后续输入,才参与新的判断。System rules, the user request, and recent conversation enter the current input. Preferences can be injected automatically within a budget. Past tasks and daily notes are searched through memory recall; experience files and Skills are read through Read. Retrieved information contributes to a new decision once it enters a subsequent input.システム規則、ユーザーの依頼、直近の会話が現在の入力に入ります。設定された上限内で好みを自動注入し、過去のタスクや日記はmemory recallで検索、経験ファイルやSkillsはReadで読み込みます。取り出した情報が後続の入力に入ることで、新しい判断に使われます。

静态图Static figure静止図记忆怎样回到输入
偏好按预算注入;其余资料按需取回。模型使用的是实际组装出的输入。Preferences are injected within a budget; other material is fetched when needed. The model uses the input actually assembled.好みは上限内で注入し、その他の資料は必要に応じて取得します。モデルが使うのは実際に組み立てられた入力です。
图注与口径Figure notes図注と評価条件

箭头表示信息进入输入的路径。资料柜不会整库自动注入;原始轨迹也不会自动回放。Arrows show paths into the input. Neither the entire memory store nor the raw trace is automatically replayed.矢印は入力への情報経路です。記憶ストア全体や元の軌跡を自動で再生するわけではありません。

Skills 提供操作手册;经验文件保存已验证的做法。两者都可以读,但来源与更新方式不同。长历史被压缩后,工作台上还会放一份摘要和近期原文,帮助模型接着做。Skills provide operating guides; experience files hold verified practices. Both can be read, but they have different sources and update paths. After a long history is compressed, the workbench also carries a summary and recent verbatim messages so the model can continue.Skillsは操作手順、経験ファイルは検証済みのやり方を提供します。どちらも読み込めますが、出所と更新方法が異なります。長い履歴を圧縮した後は、要約と直近の原文を作業台に残し、作業を続けます。

什么值得保存,谁来保存What gets saved, and who saves it何を、誰が保存するのか

内容Content内容写入时机When it is written書き込むタイミング再次使用How it returns再び使う方法
偏好Preferences好みMainAgent 显式记住、修改或删除MainAgent explicitly remembers, revises, or forgetsMainAgentが明示的に記録・変更・削除按预算自动注入,也可搜索Budgeted automatic injection, or recall上限内で自動注入、または検索
任务记录Task recordsタスク記録Organizer 完成带 TaskCard 的任务Organizer completes a task with a TaskCardOrganizerがTaskCard付きタスクを完了搜索摘要与完整轨迹Search summaries and full traces要約と完全な軌跡を検索
日记Daily notes日記接近压缩阈值时,框架提炼并写入The framework extracts notes near the compaction threshold圧縮閾値に近づくとフレームワークが抽出・保存需要时搜索Recall when needed必要なときに検索
经验文件Experience files経験ファイルMainAgent 用文件工具维护已验证做法MainAgent maintains verified practices with file toolsMainAgentがファイルツールで検証済みの知見を更新先读索引,再读相关文件Read the index, then relevant files索引を読み、関連ファイルを開く

在挂载统一记忆的同一次运行中,MainAgent 与子 Agent 共用记忆上下文;只有 MainAgent 可以增删改偏好,子 Agent 只读。普通问答没有经过 Organizer 的任务完成钩子,就不会自动变成那类任务记录。Within a run where unified memory is mounted, MainAgent and its subagents share the memory context. Only MainAgent can change preferences; subagents have read-only access. Ordinary chat that does not pass through Organizer’s completion hook does not automatically produce that kind of task record.統合記憶が接続された同一実行内では、MainAgentと子エージェントが記憶コンテキストを共有します。好みを変更できるのはMainAgentだけで、子エージェントは読み取り専用です。Organizerの完了フックを通らない通常の会話は、この種類のタスク記録には自動保存されません。

日记也有独立的写入流程:在接近上下文上限时,额外调用模型,从选取的近期内容中提炼可保存的信息。它没有备份每一条工具返回,也不会在每一轮都执行。经验文件则由 Agent 主动编辑。Daily notes have a separate write path. Near the context threshold, an extra model call extracts useful information from selected recent content. This is neither a backup of every tool response nor a per-turn operation. Experience files are edited explicitly by the agent.日記には独立した書き込み経路があります。文脈の閾値に近づくと追加のモデル呼び出しで、選ばれた直近の内容から保存すべき情報を抽出します。すべてのツール結果をバックアップする処理ではなく、毎ターン動くわけでもありません。経験ファイルはエージェントが明示的に編集します。

历史太长,先清理,再考虑摘要A long history: clear old results first履歴が長くなったら、まず古い結果を整理する

一次长任务会积累大量工具输出。这个实现先尝试替换已经过时的工具正文,保留调用与返回的对应关系,并保护近期完整轮次、Skill 读取和工具发现结果。如果能腾出足够空间,就直接继续。Long tasks accumulate bulky tool outputs. This implementation first tries replacing eligible old tool bodies, preserving call–result pairing and protecting recent complete rounds, Skill reads, and tool-discovery results. If that frees enough space, execution continues directly.長いタスクでは大量のツール出力が蓄積します。この実装はまず、対象となる古いツール本文の置換を試します。呼び出しと結果の対応を保ち、直近の完全なラウンド、Skillの読み出し、ツール探索結果を保護します。十分な空きができれば、そのまま続行します。

清理不够时,放弃这次清理草案,将此前的较早历史交给模型总结。新输入由系统规则、历史摘要和近期完整原文组成,再补回预算内的已读 Skills、已发现工具的名称与重新查询提示,以及最新环境状态。If cleanup is insufficient, the proposed cleanup is discarded. Earlier history from before this attempt is sent to the model for summarization. The new input combines system rules, a history summary, and recent intact rounds, with budgeted restoration of read Skills, discovered tool names and re-query guidance, and refreshed environment state.整理だけでは足りなければ、その整理案を破棄し、今回の整理前にあった古い履歴をモデルで要約します。新しい入力はシステム規則、履歴要約、直近の完全な原文から構成されます。さらに上限内で既読Skills、発見済みツール名と再照会の指示、最新の環境状態を戻します。

静态图Static figure静止図上下文压缩的两条路径
先试算旧工具正文的过期替换。未达标时,摘要使用本次清理前的历史;两条路径都保留近期工作的连续性。First plan expiration of old tool bodies. If the target is not met, summarize history from before that cleanup attempt. Both paths preserve continuity of recent work.まず古いツール本文の期限切れ処理を試算します。条件を満たさなければ、今回の整理前の履歴を要約します。どちらも直近の作業のつながりを保ちます。
图注与口径Figure notes図注と評価条件

日记写入是压缩附近的独立流程,可能额外调用模型;图中的本地替换步骤本身不调用摘要模型。Daily-note flushing is a separate nearby process that may call a model. The local replacement step itself does not call a summarizer.日記保存はこの前後で行う独立処理で、モデルを呼ぶ場合があります。図のローカル置換自体は要約モデルを呼びません。

摘要后恢复预算内的 Skills、工具名称与重新查询提示、最新状态;工具名不等于完整工具 schema。摘要为空时保留旧活动段。After summarization, restore budgeted Skills, tool names and re-query guidance, and fresh state. A tool name is not its full schema. An empty summary leaves the old active segment intact.要約後に上限内のSkills、ツール名と再照会指示、最新状態を戻します。ツール名は完全なschemaではありません。要約が空なら旧区間を保持します。

保留近期完整轮次很重要:最近的用户要求、模型动作和工具返回仍然连在一起。摘要承担较早背景,近期原文承担正在发生的工作。原始轨迹另行保留;下一次生成使用的是压缩后的活动段。Keeping recent rounds intact preserves the link between new user requirements, model actions, and tool responses. The summary carries older background; recent verbatim messages carry ongoing work. The raw trace remains separate. The next generation uses the compacted active segment.直近のラウンドを丸ごと残すことで、新しい依頼、モデルの動作、ツール結果のつながりが保たれます。要約が古い背景を、直近の原文が進行中の作業を担います。元の軌跡は別に保存され、次の生成には圧縮後の有効な区間を使います。

这份实现的默认预算Default budgets in this implementationこの実装のデフォルト上限

本地估算超过 200,000 tokens 时触发压缩。工具过期方案需同时满足:节省至少 2,000 tokens,剩余不超过 120,000 tokens;最近约 40,000 tokens 的完整轮次受保护。数字是这份配置的触发预算,不等于模型服务的精确计数或窗口上限。Compaction triggers when the local estimate exceeds 200,000 tokens. Tool expiration must save at least 2,000 tokens and leave no more than 120,000; roughly 40,000 tokens of recent complete rounds are protected. These are configured trigger budgets, not the model service’s exact token count or context limit.ローカル推定が200,000 tokensを超えると圧縮を開始します。ツール本文の期限切れ処理は、2,000 tokens以上削減し、残量が120,000 tokens以下になる場合に適用します。直近約40,000 tokens分の完全なラウンドを保護します。これは設定上の予算であり、モデルサービスの厳密な計数や文脈長上限ではありません。

进入摘要分支时,近期原文预算约 12,000 tokens,至少保留一个完整轮次;已读 Skill 恢复预算为 8,000 tokens。活跃偏好的注入预算为阈值的 1%,最多 2,000 tokens。日记默认提前 4,000 tokens 尝试写入。The summary branch budgets about 12,000 tokens for recent verbatim history and keeps at least one complete round. Read Skills have an 8,000-token restoration budget. Active preferences receive 1% of the context threshold, capped at 2,000 tokens. Daily-note flushing is attempted with a default lead of 4,000 tokens.要約分岐では直近の原文に約12,000 tokensを割り当て、少なくとも一つの完全なラウンドを残します。既読Skillの復元予算は8,000 tokensです。有効な好みの注入予算は閾値の1%、最大2,000 tokens。日記の書き込みはデフォルトで閾値の4,000 tokens手前から試みます。

摘要输入也有预算,超出时可能按整轮丢弃最早历史;更早已过期的工具正文不会从原始日志恢复。摘要为空则保留旧活动段,异常会向上传递。因此,原始轨迹仍需要独立保存。Summary input also has a budget; exceeding it can drop the oldest whole rounds. Tool bodies expired in earlier compactions are not restored from the raw log. An empty summary leaves the old active segment in place; exceptions propagate. The raw trace therefore still needs independent retention.要約用の入力にも上限があり、超過時には最古のラウンドから削除されることがあります。以前の圧縮で期限切れになったツール本文は、元のログから復元されません。要約が空なら旧区間を保持し、例外は上位へ伝わります。そのため、元の軌跡を独立して残す必要があります。

为什么换个任务就忘了Why a new task can start empty新しいタスクで忘れてしまう理由

关键在入口。标准任务入口为每次 attempt 创建空的临时记忆库,结束后归档;下一次 attempt 不会自动读回归档。长驻会话或直接使用配置目录的入口,才可以复用同一份用户记忆。相同的用户 ID,本身不足以保证跨任务继承。The entry point matters. The standard task entry creates an empty temporary memory store for each attempt and archives it at the end. The next attempt does not automatically reload that archive. A long-lived session, or an entry that directly uses the configured directory, can reuse the same user store. Matching user IDs alone do not guarantee continuity.実行の入口が重要です。標準のタスク入口はattemptごとに空の一時記憶ストアを作り、終了時にアーカイブします。次のattemptがそのアーカイブを自動で読むことはありません。長寿命セッションや設定ディレクトリを直接使う入口なら、同じユーザーストアを再利用できます。ユーザーIDが同じだけでは、引き継ぎは保証されません。

静态图Static figure静止図记忆能否跨过任务边界
同一个 user ID,遇到不同入口,也可能读到不同的记忆库。归档本身不会建立自动恢复路径。The same user ID can reach different memory stores through different entry points. Archiving does not create an automatic restore path.同じuser IDでも、入口によって別の記憶ストアを使うことがあります。アーカイブだけでは自動復元の経路はできません。
图注与口径Figure notes図注と評価条件

此图比较存储生命周期,不表示模型自动加载全部历史。长驻入口的存储复用,也不等于进程重启后完整会话自动恢复。This diagram compares storage lifecycles, not automatic loading of all history. Reusing a store through a long-lived entry also does not automatically restore the full conversation after a restart.この図はストアの寿命を比較しており、全履歴の自動読み込みを表していません。長寿命の入口でストアを再利用しても、再起動後に完全な会話が自動復元されるわけではありません。

同一会话继续执行,可以沿用当前状态。进程重启后,记忆库、虚拟机里的经验文件、完整对话恢复又是三件需要分别接好的事。保存成功之后,还要检查新入口读的是哪一份存储。Continuing the same session can preserve its current state. After a process restart, reconnecting the memory store, accessing experience files in the VM, and restoring the full conversation are three separate jobs. After confirming a write, check which store the new entry point actually reads.同じセッションの続行では現在の状態を引き継げます。一方、プロセス再起動後の記憶ストア接続、仮想マシン内の経験ファイルへのアクセス、完全な会話の復元は、それぞれ別に整える必要があります。保存を確認したら、新しい入口がどのストアを読むかも確認します。

压缩后,还能接着做吗Can the agent continue after compaction?圧縮した後も作業を続けられるか

一次线上压缩把 303 条消息缩到 98 条,系统规则和一份很长的 Skill 操作说明仍留在输入中,较早的对话则由摘要承接。这里有一个明确的取舍:概括过去发生的事,保留接下来还要遵守的操作规则。One production compaction reduced 303 messages to 98. System instructions and a long Skill guide stayed in the input, while a summary carried earlier conversation. The trade-off is concrete: summarize what happened, but retain the operating rules needed for the next action.本番の一回の圧縮では、303件のメッセージが98件になりました。システム指示と長いSkillの操作手順は入力に残り、古い会話は要約で引き継がれました。過去の経緯はまとめ、次の操作にも必要な規則は残す、という取捨選択です。

消息少了,能否顺利续做还要另查。比如刚创建的字段 ID、尚未完成的步骤、用户补充的限制,下一轮是否仍能找到?评估压缩应检查这些信息是否保留,并实际验证续做;仅凭消息条数,无法判断省了多少 token,也无法判断是否忘了关键内容。Fewer messages do not establish that work can resume correctly. Can the next turn still find a newly created field ID, unfinished steps, and constraints the user added? Evaluate compaction by checking that this information survives and testing continuation. Message counts alone establish neither token savings nor retention of essential information.メッセージが減っても、正しく再開できるかは別に確かめる必要があります。作成したばかりのフィールドID、未完了の手順、ユーザーが追加した制約を、次のターンでも参照できるでしょうか。圧縮の評価では、こうした情報の保持と実際の続行を確認します。件数だけではtoken削減量も、重要な情報が残ったかも判断できません。

还要分清本次任务的摘要和下一次任务的记忆:前者帮助当前会话继续,后者需要写入存储,并在新任务里重新读取。只做好压缩,并不会自动获得跨任务记忆。A summary for this task and memory for the next task have different lifecycles. The summary helps the current conversation continue. Cross-task memory must be saved and read again in the new task. Compaction alone does not provide that continuity.今回のタスクを続けるための要約と、次のタスクへ渡す記憶は分けて考えます。要約は現在の会話を支えますが、タスクをまたぐ記憶には保存と新しいタスクでの読み出しが必要です。圧縮だけでは、この引き継ぎは実現しません。

排查“忘记”,沿一条信息走一遍Debug forgetting by following one fact一つの情報をたどって「忘れた」を調べる

比如“报告先给结论”这条偏好:先看它是否写入当前使用的记忆库,再看有没有被注入或检索,最后查看实际发送给模型的输入。如果信息已经在输入里,才继续分析模型是否遵循。这样可以把存储隔离、读取缺失、压缩遗漏和执行偏差分开。Take the preference ‘put the conclusion first.’ Check whether it was written to the store currently in use, whether it was injected or recalled, and whether it appears in the actual model input. Once it is present, examine whether the model followed it. This separates isolated storage, missing retrieval, compression loss, and execution errors.「報告は結論から」という好みを例にします。今使っているストアに保存されたか、注入または検索されたか、実際のモデル入力に入っているかを順に確認します。入力にあれば、モデルが従ったかを調べます。保存先の分離、読み出し漏れ、圧縮による欠落、実行上の逸脱を切り分けられます。

一个好用的记忆系统,需要明确保存什么、何时读取、能跨过哪些边界。最有价值的检查点,是下一次模型调用真正拿到了哪些信息。A useful memory system makes clear what is saved, when it is read, and which boundaries it survives. The most useful checkpoint is the information that actually reaches the next model call.使いやすい記憶システムでは、何を保存し、いつ読み、どの境界を越えて引き継げるかが明確です。最も有用な確認地点は、次のモデル呼び出しに実際に届いた情報です。

图源与代码Figures and code図とコード

图中文字翻译Figure translations図の翻訳 · 流程与交互数据Flow and interaction dataフローと操作データ · 交互代码Interaction code操作部分のコード

放大的流程图