@ agent-relay/会话
代理中继的可移植会话连续性 。 SDK保持一个稳定的中继 跨越机器和人工智能的会话ID,同时保留不可改变性 拥有者、当前方向盘和完整的控制转移审计线索.
安装
npm install @agent-relay/session
设定 RELAYHISTORY_URL 到中继历史部署。 客户端接受 URL
有无 /v1 后缀.
export RELAYHISTORY_URL=https://history.agentrelay.com
export RELAYHISTORY_TOKEN=...
RELAYHISTORY_ACCESS_TOKEN 财务报告和审定财务报表 RELAY_AGENT_TOKEN 作为符号支持
堕倒.
已完成的会话重放也加入了全工作空间的中继广播对话.
设定 RELAY_WORKSPACE_KEY (或 AGENT_RELAY_WORKSPACE_KEY和,对于不违约
部署, RELAY_BASE_URL编辑 relay session replay CLI 使用工作空间
当两个工作空间键变量都不是时, 已经为当前工程选中
设置.
开始并日志会话
import { SessionClient } from '@agent-relay/session';
const sessions = new SessionClient({ cli: 'claude', node: 'danny-mac' });
const owner = {
userId: 'usr_danny',
email: '[email protected]',
displayName: 'Danny',
};
const session = await sessions.createSession({
cli: 'claude',
node: 'danny-mac',
owner,
});
// Best effort: failures do not interrupt the harness. Pass onWriteError to
// SessionClient when the host wants logging or telemetry for failed writes.
void sessions.writeTurn({
sessionId: session.sessionId,
role: 'user',
content: 'Continue the migration.',
actor: owner,
});
再来一次
const sessions = new SessionClient({ cli: 'codex', node: 'dev-mac' });
const { session, turns, resume } = await sessions.resumeSession(relaySessionId);
if (resume.mode === 'native') {
// Only selected for a Claude-origin session resumed by Claude.
launchClaude(['--resume', resume.nativeResumeId]);
} else {
// Codex, OpenCode, Grok, Cursor, and every cross-CLI handoff use this path.
launchHarness({ prompt: resume.contextPrompt });
}
注入的提示包含命令、 归结的 Relay History 日记和 标记为引用的上下文。 编码会话是仅限日记的,包括 代码对Codex的交接.
重放已完成的多代理会话
const replay = await sessions.replaySession(relaySessionId);
console.log(replay.contextPrompt);
console.log(replay.conversation.availability);
console.log(replay.conversation.retention);
replaySession 加入中继历史翻转, 并加盖中继广播信件
同会话引用,获取每个中继广播页面,并命令添加
时间戳。 重播是整个工作空间的 所以谈话片段
尽管Relay History 日记是每个节点的,但继续横跨节点。 一个不见了
节点日记仍然可以省略节点的自带回转;回放标签
并且不推断中继历史的完整性.
每一次重放都会打印出有效的再播保留边界. partial, (中文(简体) ),
aged_out,并标出未知/未成功结果
INCOMPLETE 而不是将空谈作为代理人的证据
没有沟通。 因此,可以达到的谈话只能延伸到
作为工作空间计划的有效保留政策.
记录方向和属性
await sessions.recordSteering({
sessionId: relaySessionId,
actor: {
userId: 'usr_dev',
email: '[email protected]',
displayName: 'Dev',
},
relayMessageId: '213570121302978560',
});
const trailers = await sessions.getGitTrailers(relaySessionId);
// Append trailers.join('\n') to the commit message.
拖车包括去重复 Co-authored-by 身份加稳定
Relay-Session-*,活性演员,起源-CLI,和起源-节点归属.
中继历史电线合同
SDK 使用现有的 RelayHistory 日记端点 :
POST /v1/sessions/:sessionId/turnsGET /v1/sessions/:sessionId/turns
创建和引导是持久的系统,其元数据充满
RelaySession 示意图. 普通用户、助手和系统转换使用
同样的日记。 这使得后端日记成为真理的唯一来源
关于对话的背景和身份审计线索.