@agent-assistant/continuation

中文文档
0.4.37发布于 2026/10/04TypeScriptES Module构建来源已验证近 30 天下载 6092

Bounded continuation primitive — turns resumable harness outcomes into explicit state, validated resume triggers, and real follow-up delivery

原始使用文档
文档目录20 节
  1. Overview
  2. Installation
  3. Quick start
  4. API Reference
  5. createContinuationRuntime(config)
  6. ContinuationRuntime
  7. create(input)
  8. resume(input)
  9. stop(input)
  10. Continuation lifecycle
  11. Wait conditions and triggers
  12. TTL defaults
  13. Adapters
  14. ContinuationHarnessAdapter
  15. ContinuationDeliveryAdapter
  16. ContinuationSchedulerAdapter
  17. ContinuationStore
  18. Delivery state
  19. Error types
  20. Boundaries

@agent-assistant/continuation

The bounded runtime primitive that turns resumable harness outcomes into explicit state, validated resume triggers, and real follow-up delivery.

Overview

A continuation begins when @agent-assistant/harness stops a turn honestly but not finally — the assistant asked a clarifying question, an action is waiting for approval, or work was deferred because an external process is still pending. The continuation package owns everything that happens after that stop:

  • persisting the resumable turn state as a typed ContinuationRecord
  • accepting an explicit resume trigger that matches what the continuation is waiting for
  • validating liveness (not expired, not already terminal, within max attempt bounds)
  • re-entering harness with a new bounded turn
  • recording follow-up delivery state

What it does not own:

  • bounded turn execution → @agent-assistant/harness
  • session identity/lifecycle → @agent-assistant/sessions
  • transport delivery → @agent-assistant/surfaces
  • approval/risk decisions → @agent-assistant/policy
  • long-term memory → @agent-assistant/memory
  • generic scheduled nudges → @agent-assistant/proactive

Installation

npm install @agent-assistant/continuation

Quick start

import { createContinuationRuntime, InMemoryContinuationStore } from '@agent-assistant/continuation';

const runtime = createContinuationRuntime({
  store: new InMemoryContinuationStore(),
  harness: myHarnessAdapter,    // implements ContinuationHarnessAdapter
  delivery: myDeliveryAdapter,  // optional: implements ContinuationDeliveryAdapter
});

// 1. After harness returns needs_clarification:
const { continuation } = await runtime.create({
  assistantId: 'sage',
  sessionId: 'session-123',
  originTurnId: 'turn-abc',
  harnessResult,  // the HarnessResult with outcome: 'needs_clarification'
});
// continuation.status === 'pending'
// continuation.waitFor.type === 'user_reply'

// 2. When the user replies:
const result = await runtime.resume({
  continuationId: continuation.id,
  trigger: {
    type: 'user_reply',
    message: { id: 'msg-2', text: 'London', receivedAt: new Date().toISOString() },
    receivedAt: new Date().toISOString(),
  },
});
// result.continuation.status === 'completed'
// result.harnessResult — the result of the resumed bounded turn

// 3. Cancel when no longer needed:
await runtime.stop({
  continuationId: continuation.id,
  reason: 'cancelled_by_user',
});

API Reference

createContinuationRuntime(config)

Returns a ContinuationRuntime bound to the provided config.

interface ContinuationConfig {
  store: ContinuationStore;
  harness: ContinuationHarnessAdapter;
  delivery?: ContinuationDeliveryAdapter;
  scheduler?: ContinuationSchedulerAdapter;
  clock?: ContinuationClock;
  trace?: ContinuationTraceSink;
  defaults?: ContinuationDefaults;
}

ContinuationRuntime

MethodDescription
create(input)Create a continuation from a resumable harness result
resume(input)Resume a pending continuation with an explicit trigger
stop(input)Terminate a continuation with a truthful reason
get({ continuationId })Retrieve a continuation record by id

create(input)

Accepts a resumable HarnessResult (needs_clarification, awaiting_approval, deferred) and returns a ContinuationCreateResult containing the new ContinuationRecord.

Rejects non-resumable outcomes (completed, failed) with ContinuationInvalidInputError.

The wait condition is derived from the outcome:

OutcomeWait condition
needs_clarificationuser_reply
awaiting_approvalapproval_resolution — requires approvalId in continuation state or metadata
deferred (default)external_result — requires operationId in continuation state or metadata
deferred + metadata.scheduledWake: truescheduled_wake

resume(input)

Accepts a ContinuationResumeTrigger and re-enters harness if all validation passes:

  1. Record exists
  2. Record status is pending
  3. Current time is before expiresAt
  4. Trigger type matches waitFor.type
  5. Correlation identifiers match (approvalId, operationId)
  6. resumeAttempts < maxResumeAttempts

Approval denied: if trigger is approval_resolution with decision: 'denied', harness is not called and the record is marked cancelled with reason approval_denied.

Re-pending: if harness returns another resumable outcome, the record is re-pended with a new wait condition (not a new record).

stop(input)

Terminal reasons map to statuses:

ReasonStatus
completedcompleted
cancelled_by_user, cancelled_by_product, approval_deniedcancelled
superseded_by_newer_turnsuperseded
expired_ttlexpired
All othersfailed

Stop is idempotent: calling stop on an already-terminal record returns it unchanged.


Continuation lifecycle

                    ┌─────────────┐
                    │   pending    │
                    └──────┬───────┘
                           │
         ┌─────────────────┼─────────────────┐
         │                 │                  │
         ▼                 ▼                  ▼
  ┌────────────┐  ┌────────────────┐  ┌──────────────┐
  │  resuming   │  │    expired     │  │  cancelled/  │
  └──────┬─────┘  └────────────────┘  │  superseded  │
         │                            └──────────────┘
  ┌──────┼──────┐
  │      │      │
  ▼      ▼      ▼
completed failed pending (re-pend)

Wait conditions and triggers

Wait conditionResume trigger
user_reply{ type: 'user_reply', message, receivedAt }
approval_resolution{ type: 'approval_resolution', approvalId, decision, resolvedAt }
external_result{ type: 'external_result', operationId, resolvedAt, payload? }
scheduled_wake{ type: 'scheduled_wake', wakeUpId?, firedAt }

TTL defaults

OutcomeDefault TTL
needs_clarification1 hour (3,600,000 ms)
awaiting_approval24 hours (86,400,000 ms)
deferred1 hour
scheduled_wake1 hour

Override defaults via config.defaults or per-record via create({ bounds }).


Adapters

ContinuationHarnessAdapter

interface ContinuationHarnessAdapter {
  runResumedTurn(input: ContinuationResumedTurnInput): Promise<HarnessResult>;
}

Products implement this to wire turn-context assembly before calling harness.

ContinuationDeliveryAdapter

interface ContinuationDeliveryAdapter {
  deliver(input: ContinuationDeliveryInput): Promise<ContinuationDeliveryResult>;
}

Optional. When present, called after a resumed turn produces a user-visible terminal result.

ContinuationSchedulerAdapter

interface ContinuationSchedulerAdapter {
  scheduleWake(input: { continuationId: string; wakeAtMs: number }): Promise<{ wakeUpId: string }>;
  cancelWake?(wakeUpId: string): Promise<void>;
}

Optional. Required only for scheduled_wake continuations.

ContinuationStore

interface ContinuationStore {
  put(record: ContinuationRecord): Promise<void>;
  get(continuationId: string): Promise<ContinuationRecord | null>;
  delete?(continuationId: string): Promise<void>;
  listBySession?(sessionId: string): Promise<ContinuationRecord[]>;
}

Only put and get are required. Use InMemoryContinuationStore for tests and development.


Delivery state

StatusMeaning
not_applicableNo delivery adapter configured
pending_deliveryDelivery adapter present; delivery not yet attempted
deliveredFollow-up successfully delivered
suppressed_session_reengagedUser re-engaged; follow-up suppressed
suppressed_supersededContinuation superseded before delivery
suppressed_expiredContinuation expired before delivery
delivery_failedDelivery adapter returned failure

Error types

ErrorThrown when
ContinuationNotFoundErrorRecord id not in store
ContinuationExpiredErrorRecord TTL has passed
ContinuationAlreadyTerminalErrorResume called on non-pending record
ContinuationTriggerMismatchErrorTrigger type or correlation id mismatch
ContinuationInvalidInputErrorInvalid creation input (bad outcome, missing required fields)

Boundaries

  • Harness emits resumable outcomes. Continuation operationalizes them. Harness is not affected by this package.
  • Proactive vs continuation: if there is no originating stopped turn id, it is proactive. If the assistant is resuming a known unfinished turn lineage, it is continuation.
  • Continuation is not a scheduler. Scheduled wake is a trigger type, not a scheduler implementation.
  • Continuation is not a memory system. It stores short-lived operational state for one unfinished turn lineage only.
  • v1 scope: one live record per origin turn. Multi-branch continuation graphs are explicitly out of scope.

版本与发布记录

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

版本发布日期距今
0.4.37latest2026/10/041 个月前
0.4.362026/10/041 个月前
0.4.352026/05/235 个月前
0.4.332026/05/155 个月前
0.4.322026/05/125 个月前
0.4.312026/05/086 个月前

关于 @agent-assistant/continuation 的常见问题

@agent-assistant/continuation 是什么?

Bounded continuation primitive — turns resumable harness outcomes into explicit state, validated resume triggers, and real follow-up delivery

如何安装 @agent-assistant/continuation?

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

@agent-assistant/continuation 支持 TypeScript 吗?

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

@agent-assistant/continuation 支持 ESM 还是 CommonJS?

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

@agent-assistant/continuation 可以商用吗?

@agent-assistant/continuation 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@agent-assistant/continuation 的下载量有多少?

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

@agent-assistant/continuation 还在维护吗?

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