@agent-assistant/continuation
限定运行时间的原始方式,将可恢复的利用结果转化为明确状态,验证恢复触发,以及真正的后续交付.
概览
续作从 @agent-assistant/harness 这名助理诚实地但最后地提出了澄清问题,一项行动正在等待批准,或者由于外部程序仍未完成而推迟工作。 续作包拥有该站后发生的一切:
- 将可恢复的转折状态作为已键入
ContinuationRecord - 接受一个与续作中等待的匹配的明确恢复触发器
- 验证活性( 未过期, 尚未终止, 在最大尝试范围内)
- 以新的有界限的转弯重新入手
- 记录后续执行状态
它不拥有的东西:
- 限定的回合执行 +
@agent-assistant/harness - 段 次 页 次
@agent-assistant/sessions - (a) 运输
@agent-assistant/surfaces - 核准/风险决定
@agent-assistant/policy - 长期记忆
@agent-assistant/memory - 通用排行榜
@agent-assistant/proactive
安装
npm install @agent-assistant/continuation
快开始
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 参考
createContinuationRuntime(config)
回返a ContinuationRuntime 绑在提供配置.
interface ContinuationConfig {
store: ContinuationStore;
harness: ContinuationHarnessAdapter;
delivery?: ContinuationDeliveryAdapter;
scheduler?: ContinuationSchedulerAdapter;
clock?: ContinuationClock;
trace?: ContinuationTraceSink;
defaults?: ContinuationDefaults;
}
ContinuationRuntime
| 方法 | 说明 |
|---|---|
create(input) | 利用可更新的牵引结果创建续作 |
resume(input) | 以明确触发方式恢复待续 |
stop(input) | 以真实的理由终止续作 |
get({ continuationId }) | 通过 id 检索续作记录 |
create(input)
接受一个可恢复的 HarnessResult (单位:千美元)needs_clarification, (中文(简体) ), awaiting_approval, (中文(简体) ), deferred返回 a ContinuationCreateResult 包含新的 ContinuationRecord。 。 。 .
拒绝不可恢复的结果 (单位:千美元)completed, (中文(简体) ), failed与 ContinuationInvalidInputError。 。 。 .
等待条件源于结果:
| 结果 | 等待条件 |
|---|---|
needs_clarification | user_reply |
awaiting_approval | approval_resolution 要求 approvalId 状态或元数据 |
deferred (默认) | external_result 要求 operationId 状态或元数据 |
deferred + 键 metadata.scheduledWake: true | scheduled_wake |
resume(input)
接受一个 ContinuationResumeTrigger 如果所有验证都通过,则重新使用:
- 记录存在
- 记录状态为
pending - 现在的时间是以前
expiresAt - 触发类型匹配
waitFor.type - 关联标识符匹配( 核准Id, 操作) (d) 国家
resumeAttempts < maxResumeAttempts
拒绝批准: 如果触发是 approval_resolution 与 decision: 'denied',不调用并标出记录 cancelled 有理无据 approval_denied。 。 。 .
转帐: 如果调用返回另一个可重复的结果,则记录会以新的等待条件(而不是新的记录)被重新修改.
stop(input)
状态的终端原因映射 :
| 原因 | 状态 |
|---|---|
completed | completed |
cancelled_by_user, (中文(简体) ), cancelled_by_product, (中文(简体) ), approval_denied | cancelled |
superseded_by_newer_turn | superseded |
expired_ttl | expired |
| 所有其他国家 | failed |
停下来 专有: 调用一个已死记录的停止返回它不变.
连续生命周期
┌─────────────┐
│ pending │
└──────┬───────┘
│
┌─────────────────┼─────────────────┐
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────────┐ ┌──────────────┐
│ resuming │ │ expired │ │ cancelled/ │
└──────┬─────┘ └────────────────┘ │ superseded │
│ └──────────────┘
┌──────┼──────┐
│ │ │
▼ ▼ ▼
completed failed pending (re-pend)
等待条件和触发
| 等待条件 | 继续触发 |
|---|---|
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 默认
| 结果 | 默认 TTL |
|---|---|
needs_clarification | 1小时(3 600 000毫秒) |
awaiting_approval | 24小时(86 400 000毫秒) |
deferred | 1小时 |
scheduled_wake | 1小时 |
通过 config.defaults 或通过 create({ bounds })。 。 。 .
适配器
ContinuationHarnessAdapter
interface ContinuationHarnessAdapter {
runResumedTurn(input: ContinuationResumedTurnInput): Promise<HarnessResult>;
}
产品在调用绳索之前就用它来连接转折文本组装.
ContinuationDeliveryAdapter
interface ContinuationDeliveryAdapter {
deliver(input: ContinuationDeliveryInput): Promise<ContinuationDeliveryResult>;
}
可选的 当出现时,在恢复转弯后呼叫,会产生一个用户可见的终端结果.
ContinuationSchedulerAdapter
interface ContinuationSchedulerAdapter {
scheduleWake(input: { continuationId: string; wakeAtMs: number }): Promise<{ wakeUpId: string }>;
cancelWake?(wakeUpId: string): Promise<void>;
}
可选的 仅限 scheduled_wake 续行.
ContinuationStore
interface ContinuationStore {
put(record: ContinuationRecord): Promise<void>;
get(continuationId: string): Promise<ContinuationRecord | null>;
delete?(continuationId: string): Promise<void>;
listBySession?(sessionId: string): Promise<ContinuationRecord[]>;
}
仅 put 财务报告和审定财务报表 get 需要这样做。 使用 InMemoryContinuationStore 用于测试和开发.
交货状态
| 状态 | 含义 |
|---|---|
not_applicable | 没有配置送出适配器 |
pending_delivery | 交付适配器存在;尚未尝试交付 |
delivered | 后续行动成功交付 |
suppressed_session_reengaged | 用户重新参与; 后续行动被压制 |
suppressed_superseded | 交货前继续替换 |
suppressed_expired | 继续交货前过期 |
delivery_failed | 交付适配器返回失败 |
错误类型
| 错误 | 掷出时 |
|---|---|
ContinuationNotFoundError | 未保存的记录 ID |
ContinuationExpiredError | 记录 TTL 已经通过 |
ContinuationAlreadyTerminalError | 恢复未用记录 |
ContinuationTriggerMismatchError | 触发类型或关联性 ID 不匹配 |
ContinuationInvalidInputError | 无效的创建输入( 不良结果, 缺少所需的字段) |
边界
- 利用性释放出可恢复的结果。 继续运作. 这个套件不会影响机能.
- 主动对接续 : 如果没有原生的 停止转动的ID,它是主动的。 如果该助手正在恢复已知的未完成的转折行系,则继续.
- 继续不是排程. 预定的守夜是触发器 类型,而非调度器执行.
- 继续不是一个记忆系统. 它只保存一个未完成的转折线的短寿命运行状态.
- v1 范围 : 一个现场记录每个源转。 多分支接续图明显超出范围.