@agent-relay/session

中文文档
17.0.0发布于 2026/11/05Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1.1万

Cross-harness session continuity and attribution for Agent Relay

原始使用文档
文档目录6 节
  1. Install
  2. Start and journal a session
  3. Resume from another harness
  4. Replay a completed multi-agent session
  5. Record steering and attribute commits
  6. Relayhistory wire contract

@agent-relay/session

Portable session continuity for Agent Relay. The SDK keeps one stable Relay session ID across machines and AI harnesses while preserving the immutable owner, current steerer, and full control-transfer audit trail.

Install

npm install @agent-relay/session

Set RELAYHISTORY_URL to the Relayhistory deployment. The client accepts a URL with or without the /v1 suffix.

export RELAYHISTORY_URL=https://history.agentrelay.com
export RELAYHISTORY_TOKEN=...

RELAYHISTORY_ACCESS_TOKEN and RELAY_AGENT_TOKEN are supported as token fallbacks.

Completed-session replay also joins the workspace-wide Relaycast conversation. Set RELAY_WORKSPACE_KEY (or AGENT_RELAY_WORKSPACE_KEY) and, for a non-default deployment, RELAY_BASE_URL. The relay session replay CLI uses the workspace already selected for the current project when neither workspace-key variable is set.

Start and journal a session

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,
});

Resume from another harness

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 });
}

The injected prompt contains the ordered, attributed Relayhistory journal and marks it as quoted prior context. Codex sessions are journal-only, including Codex-to-Codex handoffs.

Replay a completed multi-agent session

const replay = await sessions.replaySession(relaySessionId);

console.log(replay.contextPrompt);
console.log(replay.conversation.availability);
console.log(replay.conversation.retention);

replaySession joins Relayhistory turns with Relaycast messages stamped with the same session reference, fetches every Relaycast page, and orders the joined timeline by timestamp. Relaycast is workspace-wide, so the conversation slice continues across nodes even though Relayhistory journals are per-node. A missing node journal can still omit that node's private harness turns; the replay labels that limitation and does not infer cross-node Relayhistory completeness.

Every replay prints the effective Relaycast retention boundary. partial, aged_out, missing credentials, and unknown/query-failure results are marked INCOMPLETE rather than presenting an empty conversation as proof that agents did not communicate. The reachable conversation therefore extends only as far back as the workspace plan's effective retention policy.

Record steering and attribute commits

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.

Trailers include de-duplicated Co-authored-by identities plus stable Relay-Session-*, active-actor, origin-CLI, and origin-node attribution.

Relayhistory wire contract

The SDK uses the existing Relayhistory journal endpoints:

  • POST /v1/sessions/:sessionId/turns
  • GET /v1/sessions/:sessionId/turns

Creation and steering are durable system turns whose metadata carries the full RelaySession snapshot. Ordinary user, assistant, and system turns use the same ordered journal. This makes the backend journal the single source of truth for conversation context and the identity audit trail.

版本与发布记录

@agent-relay/session 共发布 78 个版本,首次发布于 2026/08/14;过去 12 个月发布了 78 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
17.0.0latest2026/11/051 天前
16.0.02026/11/041 天前
15.1.12026/11/042 天前
15.1.02026/11/033 天前
15.0.2-next.0next2026/11/024 天前
15.0.22026/11/024 天前

关于 @agent-relay/session 的常见问题

@agent-relay/session 是什么?

Cross-harness session continuity and attribution for Agent Relay

如何安装 @agent-relay/session?

在项目目录运行 npm install @agent-relay/session,或使用 pnpm add / yarn add / bun add。

@agent-relay/session 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agent-relay/session 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agent-relay/session 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@agent-relay/session 可以商用吗?

@agent-relay/session 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@agent-relay/session 的下载量有多少?

根据 npm 官方下载统计,@agent-relay/session 在 2026/10/05 – 2026/11/03 这 30 天内被下载 11,031 次,日均约 368 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agent-relay/session 还在维护吗?

最新版本 17.0.0 发布于 2026/11/05(1 天前);至今共发布 78 个版本,其中过去 12 个月发布了 78 个;首次发布于 2026/08/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。