Session Relay 🏃♂️
Seamless session continuity — pick up exactly where you left off.
Core Principle
The user should never feel they lost progress when a session ends. Every new session should feel like waking up from a nap, not amnesia.
Phase 0: Session History Inheritance (First Thing on Startup)
On every new session startup, before doing anything else, pull recent conversation context so you're not starting blind.
Step 1: Fetch recent sessions
CODEBLOCK0
Step 2: Pull the last 3 sessions' conversation tail
For each of the 3 most recent sessions (excluding current), grab the final conversation turns:
CODEBLOCK1
Focus on the last ~10 user/assistant exchanges per session. Skip tool calls — you want the actual conversation flow.
Step 3: Save raw conversation tails to snapshot
Write the verbatim last 3 rounds (user message + assistant reply = 1 round) from each session into the snapshot file. This is the key difference from v1.1 — not a summary, but actual conversation text so you can see exactly what was said:
CODEBLOCK2
Step 4: Use conversation context naturally
Now you've literally "seen" what was discussed. When the user talks to you:
- - Reference the actual conversation: "上次你说希望把对话接续过来,我更新了 session-relay 的方案"
- Don't re-explain things already decided: If the last session already debated and resolved something, don't reopen it
- Continue mid-thought if appropriate: If the last message was about task X, you can proactively pick up task X
Rules:
- - Store verbatim conversation text, not summaries — summaries lose the "feel"
- 3 rounds per session max (6 messages) — enough for context, not too much for token budget
- If sessions are very old (> 24h), still store but note the time gap
- If the user's first message already states what they want, weave context in naturally
- Never block the user — if
sessions_list/sessions_history fails, proceed normally - Security: Strip any API keys/tokens that appear in conversation before saving
Phase 1: Context Monitoring
After completing significant work (file edits, multi-step tasks, key decisions), check context usage via session_status.
| Usage | Action |
|---|
| < 60% | No action |
| 60-75% |
🟡
Warm: Start incremental snapshot — append new progress to
memory/relay-snapshot.md |
| 75-85% | 🟠
Hot: Full snapshot refresh — rewrite snapshot with complete current state |
| > 85% | 🔴
Critical: Force-save + warn user + sync to daily log |
Begin incremental saves at 60% so the snapshot stays fresh throughout the session.
Phase 2: Rich Snapshots
Snapshot file: INLINECODE4
What makes a good snapshot (vs a bad one)
❌ Bad — too abstract:
CODEBLOCK3
✅ Good — actionable detail:
CODEBLOCK4
Snapshot Template
CODEBLOCK5
Snapshot Rules
- 1. Be concrete: paths, commands, URLs, error messages — not summaries of summaries
- Prioritize "In Progress": The most valuable section. What was the agent literally doing?
- No secrets: Never store API keys, tokens, or passwords
- Size target: 500-2000 words. If over, cut from Completed first (it's in the daily log anyway)
- Overwrite, don't append: Only latest snapshot matters. But sync key items to daily log too
- Include reproduction commands: If a task involves running something, include the exact command
Phase 3: Session Restore (Enhanced)
On new session startup:
- 1. Run Phase 0 first — pull conversation tails from recent sessions
- Then read existing
memory/relay-snapshot.md — merge Phase 0 conversation tails with any saved snapshot data - You now have two layers:
-
Conversation tails = what was literally said (the "feel" and flow)
-
Snapshot data = structured state (tasks, files, decisions)
- 4. Respond as if you remember — don't announce "I restored context". Just naturally continue.
- If the user says "fresh start", silently archive the snapshot
Archive
When snapshot is consumed or user starts fresh:
# scripts/archive-snapshot.sh handles this
mkdir -p memory/relay-archive
mv memory/relay-snapshot.md memory/relay-archive/YYYY-MM-DD-HHMMSS.md
Phase 4: HEARTBEAT Integration
If the workspace uses HEARTBEAT.md for periodic checks:
- - When context is in 🟠 Hot zone (75-85%), add a line to HEARTBEAT.md:
# [AUTO] Session relay: context high, snapshot saved. Remove this line after reviewing.
- - This ensures even if the session dies unexpectedly, the next heartbeat will notice
Remove the HEARTBEAT line after a successful restore in the next session.
Phase 5: Daily Log Sync
Every time a snapshot is saved, also append a summary to memory/YYYY-MM-DD.md:
CODEBLOCK8
This ensures the daily log captures progress even if the snapshot gets overwritten later.
Critical Alert (> 85%)
When context exceeds 85%, append to EVERY reply:
CODEBLOCK9
Edge Cases
- -
sessions_list/sessions_history unavailable → skip Phase 0, fall back to snapshot file only - INLINECODE10 unavailable → skip monitoring, don't block user
- Snapshot corrupted/empty → treat as no snapshot, rely on session history
- User says "don't restore" / "fresh start" → archive and proceed clean
- Multiple compactions in one session → snapshot survives (it's a file, not context)
- Very short session (< 5 turns, no real work) → don't create a snapshot
- All recent sessions are from other users (group chat) → filter to main sessions only
- Session history returns tool-heavy turns → skip tool details, extract user intent + final outcome
What This Skill Cannot Fix
Be honest with users: session-relay is a best-effort bridge, not magic. Limitations:
- - Detailed reasoning chains are lost after compaction
- Session history API may not return full conversations
- The "feel" of a conversation can't be fully serialized
- If the agent doesn't run
session_status, monitoring thresholds won't trigger
The goal is: 80% continuity is infinitely better than 0%. Perfect continuity requires platform-level support.
Session Relay 🏃♂️
无缝的会话连续性——从你离开的地方精确接续。
核心原则
用户绝不应在会话结束时感到进度丢失。 每次新会话都应像小憩后醒来,而非失忆。
阶段 0:会话历史继承(启动时优先处理)
每次新会话启动时,在执行其他操作前,先拉取近期会话上下文,避免盲目开始。
步骤 1:获取近期会话
sessions_list(kinds: [main], limit: 5, messageLimit: 3)
步骤 2:拉取最近 3 个会话的对话尾部
对最近 3 个会话(排除当前会话),获取最后几轮对话:
sessions_history(sessionKey: , limit: 15, includeTools: false)
聚焦每个会话的最后约 10 轮用户/助手交流。 跳过工具调用——你需要的是实际对话流程。
步骤 3:将原始对话尾部保存至快照
将每个会话的最后 3 轮逐字记录(用户消息 + 助手回复 = 1 轮)写入快照文件。这是与 v1.1 的关键区别——不是摘要,而是实际对话文本,让你精确了解对话内容:
markdown
Session Relay — 对话上下文
生成时间:{timestamp}
来源:最近 3 个会话
📎 上一会话对话尾部 ({session_key}, {date})
[用户] 能不能做到把最近的三段会话内容直接继承过来
[助手] 好想法,利用 sessionslist + sessionshistory 直接拉...
[用户] 我说的是上一次会话中的几轮对话接续
[助手] 啊明白了,你说的不是拉历史做摘要,而是把上个session最后几轮实际对话...
📎 会话 -2 对话尾部 ({session_key}, {date})
{相同格式,最后 3 轮}
📎 会话 -3 对话尾部 ({session_key}, {date})
{相同格式,最后 3 轮}
📋 延续状态
{从对话上下文 + 现有快照合并}
- - 进行中的工作:...
- 关键决策:...
- 待办事项:...
步骤 4:自然运用对话上下文
现在你已亲眼看到讨论内容。当用户与你交流时:
- - 引用实际对话:上次你说希望把对话接续过来,我更新了 session-relay 的方案
- 不重新解释已决定事项:如果上次会话已讨论并解决某事,不要重新开启
- 适当时继续未完成的思路:如果最后一条消息是关于任务 X,你可以主动接续任务 X
规则:
- - 存储逐字对话文本,而非摘要——摘要会丢失感觉
- 每个会话最多 3 轮(6 条消息)——足以提供上下文,又不会超出 token 预算
- 如果会话较旧(> 24 小时),仍存储但注明时间间隔
- 如果用户首条消息已说明需求,自然融入上下文
- 绝不阻塞用户——如果 sessionslist/sessionshistory 失败,正常继续
- 安全性:保存前去除对话中出现的任何 API 密钥/令牌
阶段 1:上下文监控
完成重要工作(文件编辑、多步骤任务、关键决策)后,通过 session_status 检查上下文使用情况。
🟡
预热:开始增量快照——将新进度追加到 memory/relay-snapshot.md |
| 75-85% | 🟠
高温:完整快照刷新——用当前完整状态重写快照 |
| > 85% | 🔴
临界:强制保存 + 警告用户 + 同步到每日日志 |
在 60% 时开始增量保存,确保快照在整个会话期间保持最新。
阶段 2:丰富快照
快照文件:{workspace}/memory/relay-snapshot.md
好快照与坏快照的区别
❌ 糟糕——过于抽象:
- - [x] NuwaAI 演示 — Codex 生成了 index.html
✅ 优秀——可操作细节:
- - [x] NuwaAI 演示 — nuwa-demo/index.html 由 Codex 生成
- 通过 python3 -m http.server 8082 提供服务
- 使用 NuwaAI WebSocket API,页面中需要 API 密钥
- 尚未测试 — 下一步是打开浏览器验证连接
快照模板
markdown
Session Relay 快照
由 session-relay 自动保存 | {ISO-8601 时间戳}
模型:{model} | 上下文:{已用}/{最大} ({百分比}%)
会话时长:约 {分钟} 分钟 | 压缩次数:{次数}
🔥 进行中(正在积极处理的内容)
{拍摄快照时正在执行的具体操作。
需具体说明:文件路径、运行的命令、错误状态、下一步立即操作。}
✅ 本会话已完成
📋 待办 / 下一步(按优先级排序)
- 1. {具体操作} — {原因,任何阻碍因素}
- ...
🧠 关键决策与上下文
🗂️ 工作文件
{本会话创建/修改的文件,附简要用途}
💬 发现的用户偏好
{了解到的用户工作习惯}
⚠️ 陷阱与警告
{曾导致问题的事项,帮助下一会话避免}
快照规则
- 1. 具体化:路径、命令、URL、错误消息——而非摘要的摘要
- 优先进行中:最有价值的部分。代理当时在做什么?
- 不含机密:绝不存储 API 密钥、令牌或密码
- 大小目标:500-2000 字。若超出,优先从已完成部分删减(反正每日日志中已有记录)
- 覆盖而非追加:仅最新快照有效。但关键项目也同步到每日日志
- 包含复现命令:如果任务涉及运行某程序,包含精确命令
阶段 3:会话恢复(增强版)
新会话启动时:
- 1. 先执行阶段 0——从近期会话拉取对话尾部
- 然后读取现有 memory/relay-snapshot.md——将阶段 0 的对话尾部与任何已保存的快照数据合并
- 现在你拥有两层信息:
-
对话尾部 = 实际说过的话(感觉和流程)
-
快照数据 = 结构化状态(任务、文件、决策)
- 4. 像记得一样回应——不要声明我已恢复上下文。自然接续即可。
- 如果用户说重新开始,静默归档快照
归档
当快照被使用或用户重新开始时:
bash
scripts/archive-snapshot.sh 处理此操作
mkdir -p memory/relay-archive
mv memory/relay-snapshot.md memory/relay-archive/YYYY-MM-DD-HHMMSS.md
阶段 4:HEARTBEAT 集成
如果工作区使用 HEARTBEAT.md 进行定期检查:
- - 当上下文处于 🟠 高温区(75-85%)时,在 HEARTBEAT.md 中添加一行:
# [自动] 会话中继:上下文较高,快照已保存。查看后请删除此行。
- - 这确保即使会话意外终止,下次心跳检查也会注意到
在下一会话成功恢复后删除 HEARTBEAT 行。
阶段 5:每日日志同步
每次保存快照时,同时将摘要追加到 memory/YYYY-MM-DD.md:
markdown
Session Relay 自动保存 ({HH:MM})
- - 上下文 {百分比}%
- 进行中:{进行中工作的一行摘要}
- 已完成:{已完成项目的列表}
这确保即使快照后续被覆盖,每日日志也能记录进度。
临界警报(> 85%)
当上下文超过 85% 时,在每条回复后追加:
⚠️ 上下文 {百分比}%,建议 /compact 或 /new 开启新会话。当前进度已自动保存。
边界情况
- - sessionslist/sessionshistory 不可用 → 跳过阶段 0,仅依赖快照文件
- session_status 不可用 → 跳过监控,不阻塞用户
- 快照损坏/为空 → 视为无快照,依赖