Agent Memory
Overview
Agent Memory is the working-memory layer for Cursor agents. It lives beside raw/ and wiki/, not inside wiki/.
G:\我的雲端硬碟\Obsidian\Agent\
raw\
wiki\
memory\
Use memory/ for session metadata, cross-agent lookup, and manual archive cleanup. Do not treat it as wiki content, and do not update wiki/index.md or wiki/log.md for ordinary Memory operations unless the user explicitly asks to document the process in the Wiki.
Default usage model: most chats only get an automatic idle placeholder. Promote to active only when there is real work to record. Users rarely close sessions one by one; say 整理 memory to delete idle rows and mark overdue active sessions as stale, and explicitly archive finished sessions that have snapshots.
Paths
Memory root: G:\我的雲端硬碟\Obsidian\Agent\memory
Index: G:\我的雲端硬碟\Obsidian\Agent\memory\index.md
Sessions: G:\我的雲端硬碟\Obsidian\Agent\memory\sessions\<session-id>.md
Archive: G:\我的雲端硬碟\Obsidian\Agent\memory\archive\<session-id>\
First version rules:
memory/index.mdis the working board.memory/sessions/<session-id>.mdis the only supported session-file path if a session file exists.- Keep V1 scoped to the Memory Index, optional single session files, and archive cleanup.
Memory Index Schema
memory/index.md uses this table:
| Session ID | Agent Name | Topic | Summary | Keywords | Status | Referenced By | Started At | Updated At |
|---|---|---|---|---|---|---|---|---|
Referenced By lists Memory Session IDs of agents currently continuing from this session.
- Use
-when nobody references this session. - Use one Session ID when a single agent references it.
- Use comma-separated Session IDs when multiple agents reference it, for example:
2026-05-25-1318-cursor-main-agent, 2026-05-26-0900-cursor-main-agent. - Store referencing Session IDs, not Agent Names. Agent Name is not unique across parallel chats.
Do not use Referenced By to mean ownership. The original session row still belongs to the session that created it.
Status values in the main index:
idle
active
stale
Do not use closed or archived in the main index. Ending a session means archiving it and removing the row from memory/index.md. Archived metadata belongs in memory/archive/<session-id>/index.md.
Status Lifecycle
Status describes the work-memory lifecycle, not whether a chat window is open.
| Status | Meaning | Typical case |
|---|---|---|
idle |
Registered, but no meaningful work yet | SessionStart auto registration; Topic still 未設定; usually no session file |
active |
Real work in progress or recently updated | Manual registration, status update, or continuing from another memory session |
stale |
Had real content before, but not updated for a long time | Former active session with snapshot or meaningful Summary; candidate for review, not auto-delete |
Transitions
SessionStart auto registration → idle
Manual registration → active
Status update → active (promote from idle if needed)
Continue from source memory → current session active; source may stay active or become stale
Long time without update → active → stale (during Organize Memory)
Organize Memory → delete all idle rows; mark overdue active as stale
Archive → row removed from index; metadata kept under archive/ (sessions with snapshot only)
Promotion rules:
- SessionStart always writes
idle. - Manual registration and status update always set
active. - If a session is still
idlewhen the user asks for a status update, promote it toactivewhile writing the snapshot. - Do not promote
idletoactivejust because the chat is still open.
Stale rules (defaults; user may override when organizing):
- During Organize Memory, mark
activeasstalewhenUpdated Atis older than 14 days, the session has a snapshot or non-default Summary, andReferenced Byis-. - Do not auto-mark
idlesessions asstale; they are removed directly during organize instead.
There is no per-session closed step. When the user wants a session to end, archive it.
Snapshot Merge Policy
Session snapshots are integrated working summaries, not transcript dumps and not blind overwrites.
When a snapshot file already exists:
- Read the existing snapshot first. Never rewrite from conversation context alone.
- Merge, do not replace. Integrate the existing snapshot with new information from the current conversation.
- Preserve still-valid facts from the previous snapshot even if they no longer appear in the active chat context.
- Append or update by section using the rules below.
- Do not silently delete prior decisions, artifacts, questions, or context. If something is outdated, mark it explicitly instead of dropping it.
Section merge rules:
| Section | Merge rule |
|---|---|
Current Context |
Keep still-valid background from the old snapshot. Add or update with the latest progress. You may tighten wording, but do not drop key facts unless they are explicitly superseded. |
Decisions |
Keep prior decisions. Append new ones. If a decision is reversed, keep the old item and mark it [superseded] or move it to Superseded / Resolved. |
Files / Artifacts |
Union of old and new entries; deduplicate. |
Open Questions |
Keep unresolved items. Move resolved items to Superseded / Resolved or mark [resolved]. |
Next Actions |
Update freely, but keep still-relevant old actions unless they are done or replaced. Mark completed items [done] or move them to Superseded / Resolved. |
Continues From |
Preserve unless the user changes continuation or releases a reference. |
Superseded / Resolved |
Optional section for replaced decisions, resolved questions, and completed or abandoned actions. |
First-time snapshot creation (no existing file) still uses the template below and writes from the current conversation.
After a merge update, verify:
- Important items from the previous snapshot still appear, or are explicitly marked
[superseded],[resolved], or[done]. - New conversation progress is reflected.
Updated Atin Metadata matches the current update.
Safe Index Writes
memory/index.md can be written by hooks and agents at nearly the same time. Treat it as append-sensitive shared state.
When adding a row:
- Re-read the latest
memory/index.mdimmediately before writing. - Append only the new row.
- Do not use fixed-context patches to insert rows into the table.
- Verify the new Session ID exists after writing.
When updating a row:
- Re-read the latest
memory/index.md. - Update only the matching row.
- Verify the row still exists and reflects the intended values.
If a manual edit is unavoidable, preserve every existing row exactly. Never rewrite the whole table from an older read.
SessionStart Registration
When registering a session:
- Get the current timestamp.
- Determine a stable
Agent Name; default main-agent name iscursor-main-agent. - Generate a Memory Session ID using
YYYY-MM-DD-HHMM-agent-name. - Prepare default metadata:
Topic:未設定Summary:sessionStart 自動註冊,尚未整理主題。Keywords:sessionStart, cursor-agentStatus:idleReferenced By:-Started AtandUpdated At: current timestamp
- Append the row to
memory/index.md. - Verify the row was written.
- Only after successful write, report to the agent:
Your Memory Session ID is: <session-id>
If writing memory/index.md fails, do not report a Memory Session ID. The agent must not believe it has registered when it has not.
SessionStart creates an index row only. It does not create memory/sessions/<session-id>.md.
Manual Registration
Use this when the current agent is already running but does not have a Memory Session ID.
Trigger phrases:
註冊 memory session
補註冊 memory
手動註冊 memory
Do not borrow or guess an existing row from memory/index.md. If the agent does not explicitly know its own Memory Session ID, create a new row.
Manual registration follows the same write-and-verify rule as sessionStart registration:
- Get the current timestamp.
- Determine a stable
Agent Name; default main-agent name iscursor-main-agent. - Generate a Memory Session ID using
YYYY-MM-DD-HHMM-agent-name. - Prepare default metadata:
Topic: infer from the current conversation, or未設定if unclearSummary: one or two sentences summarizing what this session has done or decided so farKeywords:manual-registration, cursor-agent, session-snapshotStatus:activeReferenced By:-Started AtandUpdated At: current timestamp
- Write a session snapshot to
memory/sessions/<session-id>.md. - Re-read the latest
memory/index.md, then append the row. - Verify both the session snapshot and index row were written.
- Only after successful writes, report:
Your Memory Session ID is: <session-id>
If either write fails, do not report a Memory Session ID.
The session snapshot should summarize the current conversation, not dump the full transcript. If memory/sessions/<session-id>.md already exists for this Session ID, use Snapshot Merge Policy instead of creating a fresh file.
Use this template:
# Session: <session-id>
## Metadata
| Field | Value |
|---|---|
| Session ID | <session-id> |
| Agent Name | <agent-name> |
| Topic | <topic> |
| Status | active |
| Started At | <started-at> |
| Updated At | <updated-at> |
## Current Context
Summarize what has happened in this agent session so far.
## Decisions
- List decisions already made.
## Files / Artifacts
- List files, folders, hooks, skills, or wiki pages created or changed.
## Open Questions
- List unresolved questions, or write `None`.
## Next Actions
- List likely next steps, or write `None`.
## Continues From
- List source Memory Session IDs this session continues from, or write `None`.
## Superseded / Resolved
- List replaced decisions, resolved questions, or completed/abandoned actions, or write `None`.
When continuing from another session, always fill Continues From in the referencing session snapshot and update the source session's Referenced By in memory/index.md.
For manual registration, set:
Summary: summarize the current session's actual topic, decisions, and outputs
Keywords: manual-registration, cursor-agent, session-snapshot
Use 手動補註冊,已建立 session snapshot。 only as a fallback when the current session content cannot be inferred. Prefer a useful content summary because other agents use Summary to decide whether this session is relevant.
Continue Memory(接續記憶)
Use this when the current agent should pick up work from a previous memory session.
引用 memory here means continue work from a source session: update the referencing snapshot's Continues From and the source index row's Referenced By. It does not mean read-only lookup.
Trigger phrases:
接續 memory <session-id>
接續 memory session <session-id>
引用 memory <session-id>
沿用 memory <session-id>
Workflow:
- Read
memory/index.mdand locate the source session row. - Read
memory/sessions/<source-session-id>.mdwhen it exists; otherwise use index metadata only. - Ensure the current session has a Memory Session ID:
- If the current agent already has one, use it.
- If not, perform manual registration for the current session first.
- Record continuation in the current session snapshot using Snapshot Merge Policy:
- If the current agent already has a Memory Session ID, including an
idleSessionStart row, use Session Update to merge-update the snapshot, promote toactive, and fill or preserveContinues From. - If the current agent has no Memory Session ID, perform Manual Registration first, then ensure
Continues Fromlists the source Session ID. - Add or update
## Continues Fromwith the source Session ID. - Summarize what the current agent is continuing under
## Current Context. - Do not create a second index row when the current agent already has a Memory Session ID.
- If the current agent already has a Memory Session ID, including an
- Update the source session row in
memory/index.md:- Re-read the latest index.
- Update only the source row's
Referenced By. - If
Referenced Byis-or empty, set it to the current Session ID. - If it already lists other Session IDs, append the current Session ID with comma separation when it is not already present.
- Do not change the source session's Topic, Summary, Keywords, or Status unless the user explicitly asks.
- Verify:
- The current session snapshot lists the source under
Continues From. - The source index row lists the current Session ID under
Referenced By.
- The current session snapshot lists the source under
- Do not archive or close the source session automatically.
If either the current snapshot write or the source Referenced By update fails, report the continuation as incomplete. Do not claim the reference was established.
The source session remains in the index as historical context until the user archives it during organize.
Release Reference(解除引用)
Use this when a referencing session no longer depends on a source session, or before archiving a referencing session.
Trigger phrases:
解除引用 memory <source-session-id>
解除 memory 引用 <source-session-id>
release memory reference <source-session-id>
Workflow:
- Confirm the current Session ID, or the Session ID the user names as the referencing session.
- Read the latest
memory/index.mdand locate the source session row. - Remove the referencing Session ID from the source row's
Referenced By. - If no referencing Session IDs remain, set
Referenced Byto-. - Update the referencing session snapshot:
- Remove the source Session ID from
Continues From, or set the section toNoneif empty.
- Remove the source Session ID from
- Verify both writes succeeded.
When archiving a referencing session, release its references first:
- Read the referencing session snapshot
Continues Fromsection when present. - For each source Session ID listed there, remove the referencing Session ID from that source row's
Referenced By. - Then archive the referencing session normally.
If reference cleanup fails, do not archive the referencing session yet.
Session Update(狀態更新)
Use this when the current agent already has a Memory Session ID and the user asks to update, merge, or record the session state.
Trigger phrases:
狀態更新
memory session 狀態更新
更新 memory session
更新 memory 狀態
整理這個 session
整理這個 session means update the current session snapshot and index row. It is not batch organize/archive of memory/. If the user says 整理 memory or 清理 memory, use Organize Memory instead.
Requirements:
- The agent must know its own Memory Session ID for this conversation. Do not update a different session row unless the user explicitly names another Session ID.
- Always update both
memory/sessions/<session-id>.mdand the matching row inmemory/index.md. - Never update only
memory/index.mdand skip the session file. - Set
Statustoactive. Promote fromidlewhen needed. - If a snapshot already exists, follow Snapshot Merge Policy. Do not overwrite it from the current chat context alone.
Workflow:
- Get the current timestamp for
Updated At. - Confirm the Session ID (from hook context, prior report, or user).
- Read the latest
memory/index.mdand locate the row for this Session ID. - Read
memory/sessions/<session-id>.mdif it exists. - Update or create the session snapshot:
- If the file exists: apply Snapshot Merge Policy. Merge the existing snapshot with new information from the current conversation. Update
Updated Atin Metadata. PreserveStarted Atunless the user corrects it. - If the file does not exist (common after
sessionStartonly wrote the index): create it using the same template as Manual Registration, filled from the current conversation. Do not leave an index-only session after a status update.
- If the file exists: apply Snapshot Merge Policy. Merge the existing snapshot with new information from the current conversation. Update
- Re-read the latest
memory/index.md, then update only the matching row:Topic,Summary,Keywords,Status,Updated Atas needed- Set
Statustoactive - Keep
Session ID,Agent Name,Started At, andReferenced Byunchanged unless the user corrects them or explicitly releases or adds a memory reference
- Verify both writes succeeded:
- The session file exists and reflects the merged latest context
- Important items from the previous snapshot still appear, or are explicitly marked
[superseded],[resolved], or[done] - The index row still exists and
Updated Atmatches the intended timestamp
- Only after verification, report completion to the user.
Index vs session file:
| Location | Purpose |
|---|---|
memory/index.md |
Short lookup: Topic, Summary, Keywords, Status, Referenced By |
memory/sessions/<session-id>.md |
Full merged snapshot: context, decisions, artifacts, open questions, next actions, continues from, superseded/resolved |
Keep Summary in the index aligned with Current Context in the session file (same facts, index shorter).
If either write fails, say the update is incomplete. Do not claim the session was updated.
Reading Memory
When looking for previous context:
- Read
memory/index.md. - Prefer
activeandstalesessions with meaningful Topic, Summary, or Keywords. - Treat
idlerows with未設定as low-priority placeholders unless the user names a specific Session ID. - Do not read full session files by default.
- Only read
memory/sessions/<session-id>.mdwhen the user explicitly asks for the session content or when the index metadata is not enough.
Organize Memory
Use this workflow when the user says "整理 memory", "清理 memory", or asks to organize/clean the memory index.
If the user says 整理這個 session, use Session Update for the current session instead. Do not use Organize Memory for that phrase.
If the user says "封存 memory session" with a specific Session ID, use Single-session archive below instead of the default organize flow.
The user usually does not close sessions one by one. Default organize is automatic cleanup plus stale marking, not per-session archive.
Archive model:
memory/
index.md
sessions/
<session-id>.md
archive/
<session-id>/
index.md
session.md
Default organize flow(整理 memory)
When the user asks to organize memory without naming a specific session to archive, apply both steps automatically. Do not ask for confirmation unless the user gave conflicting instructions.
Step 1 — Delete all idle rows
- Read
memory/index.md. - Remove every row whose
Statusisidledirectly from the index. - Do not create
memory/archive/<session-id>/for deletedidlerows. - An
idlerow should not havememory/sessions/<session-id>.md. If it does, stop and report the inconsistency; do not delete until the user resolves it. - Do not delete rows whose
Referenced Byis not-, even if they areidle.
Step 2 — Mark overdue active rows as stale
- For each remaining row with
Statusactive:- If
Updated Atis older than 14 days - and the session has a snapshot or non-default Summary
- and
Referenced Byis- - set
Statustostale - keep
Updated Atunchanged so it still reflects the last meaningful work time
- If
- Do not auto-archive
stalerows during organize. - Do not mark recent
activerows asstale.
Step 3 — Report results
Report to the user:
- which
idleSession IDs were deleted - which
activeSession IDs were markedstale - which rows were kept as
active - which rows are protected because
Referenced Byis not-
Delete vs archive
| Case | Action |
|---|---|
idle row during default organize |
Delete from memory/index.md; no archive |
active or stale row with snapshot when user explicitly archives |
Archive under memory/archive/<session-id>/ |
Row with Referenced By not - |
Do not delete or archive until references are released |
Never direct-delete active or stale rows that have a snapshot or meaningful Summary. End those sessions only through explicit archive.
Use index Referenced By as the primary protection signal. Treat Continues From in other snapshots as a fallback when continuation was recorded incompletely and the source row's Referenced By was not updated.
Single-session archive
When the user names a specific Session ID to archive:
- Read
memory/index.md. - Identify the session row to archive.
- If the row's
Statusisidleand nomemory/sessions/<session-id>.mdexists, direct-delete the row from the index instead of archiving. Report the deletion. - If the row's
Referenced Byis not-, stop and report which Session IDs still reference it. Do not archive unless the user explicitly forces archive after releasing those references. - Read
memory/sessions/<session-id>.mdwhen it exists and collect any source Session IDs fromContinues From. - Create
memory/archive/<session-id>/. - Convert the original row into
memory/archive/<session-id>/index.md. - Check whether
memory/sessions/<session-id>.mdexists. - If it exists, move it to
memory/archive/<session-id>/session.md. - If it does not exist, stop and direct-delete the row instead of creating an empty archive.
- For each source Session ID collected from
Continues From, remove this archived Session ID from that source row'sReferenced By. - Confirm archive index exists, and the session file was moved when applicable.
- Only then remove the row from
memory/index.md. - Verify
memory/index.mdno longer contains the Session ID and the archive index exists when archive was used.
Archive only sessions with meaningful retained content. Do not create empty archive folders for placeholder rows.
If archive index creation fails, or a session file should move but fails to move, leave the original row in memory/index.md.
Archive Index Template
# Archived Session: <session-id>
## Metadata
| Field | Value |
|---|---|
| Session ID | <session-id> |
| Agent Name | <agent-name> |
| Topic | <topic> |
| Summary | <summary> |
| Keywords | <keywords> |
| Original Status | <status-before-archive> |
| Referenced By | <referenced-by-before-archive> |
| Started At | <started-at> |
| Updated At | <updated-at> |
| Archived At | <archived-at> |
## Files
- Session: ./session.md
Use this template only when a session snapshot exists or existed and was moved to ./session.md. Do not create empty archive entries for idle placeholder rows.
Common Mistakes
- Do not place Memory inside
wiki/. - Do not update Wiki index/log for ordinary Memory operations.
- Do not invent task-specific Agent Names; put task wording in
TopicorKeywords. - Do not report a Memory Session ID before confirming required Memory writes succeeded.
- Do not assume the latest
activerow is the current agent; manually register instead if unsure. - Do not assume the latest row of any status is the current agent.
- Do not use fixed-context patches to add rows to
memory/index.md; append to the latest file content. - Do not remove a row with a snapshot or meaningful Summary without archiving it first, except during default organize deletion of
idlerows. - Do not archive placeholder
idlerows; delete them during organize instead. - Do not perform a session status update by editing only
memory/index.md; always update or creatememory/sessions/<session-id>.mdas well. - Do not overwrite an existing snapshot from the current chat context alone; read the old snapshot and merge using Snapshot Merge Policy.
- Do not silently delete prior decisions, artifacts, open questions, or context during a merge update; mark them
[superseded],[resolved], or[done]instead. - Do not clear
Referenced ByorContinues Fromduring an ordinary status update unless the user explicitly releases or changes a memory reference. - Do not assume
sessionStartalready created a session file; checkmemory/sessions/and create the snapshot on status update if missing. - Do not set SessionStart registrations to
active; they start asidle. - Do not use
closedin the main index; archive instead. - Do not expect the user to close every session manually; use organize for idle cleanup and stale marking, and explicit archive for finished sessions with snapshots.
- Do not auto-archive
activeorstalesessions during default organize. - Do not archive a source session while its
Referenced Byis not-. - Do not update only the referencing session snapshot when continuing memory; also update the source row's
Referenced By. - Do not archive a referencing session before removing it from each source row's
Referenced By. - Do not store Agent Names in
Referenced By; use Memory Session IDs only.
Reference Model
Bidirectional linkage:
| Location | Field | Meaning |
|---|---|---|
| Source session index row | Referenced By |
Which sessions are currently continuing from this source |
| Referencing session snapshot | Continues From |
Which source sessions this session continues from |
Use the index column for archive protection and quick lookup. Use the snapshot section for full context inside the referencing session.