@agentplat/runtime

中文文档
1.5.1发布于 2026/11/04Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2573

Provider-neutral executable agent runtime for AgentPlat.

原始使用文档
文档目录5 节
  1. Installation (developer preview)
  2. Execution contract
  3. Runtime checkpoints
  4. Durable cognitive effects
  5. Portable heterogeneous agents

@agentplat/runtime

Provider-neutral agent runtime contracts and a small executable runtime.

Installation (developer preview)

Install the coordinated preview explicitly:

npm install @agentplat/runtime@next

Keep all @agentplat/* packages on the same release version. npm's default latest tag can point to an older preview. See the release channels for distribution status and version selection.

DefaultAgentRuntime registers provider adapters by platform, dispatches runs and streams provider events. Model-provider adapters are separate packages so applications can choose their own providers and credential strategy.

ChatAgentProvider adapts the lower-level @agentplat/model contract to one agent generation. It is appropriate for simple chat and generation. Providers such as @agentplat/provider-openai remain available when an application needs an SDK-managed agent loop and the provider-specific capabilities implemented by that adapter.

AgentStreamEvent is a discriminated union. Completed events expose normalized usage, model, finishReason and latencyMs when the provider reports them, so higher-level orchestrators can preserve real accounting instead of estimating tokens.

Execution contract

Provider adapters must treat RuntimeExecutionContext.signal as a cooperative cancellation request. Check it before starting work, pass it to downstream SDK or network calls when supported, and stop starting new work or external effects after it is aborted. This lets Room timeouts and lost execution leases cancel the underlying provider operation.

RuntimeExecutionContext.runId is the idempotency key for a logical run. It is operationally required whenever an adapter can produce an external effect or the call can be retried: reject those operations when runId is absent and reuse the same value across every retry. Forward it to providers that support idempotency keys, or use it in the adapter's deduplication mechanism, so one logical run cannot apply the same effect twice.

Runtime checkpoints

Providers may declare support for pre_action through AgentProvider.supportedCheckpoints and invoke the checkpoint callback supplied in RuntimeExecutionContext immediately before starting a tool or external effect. Higher-level runtimes use pre_step and post_output around provider execution. A denied checkpoint must stop the provider before the protected operation begins.

DefaultAgentRuntime.supportsCheckpoint lets callers fail closed before invoking a provider that cannot enforce the required action boundary. Declared support is a provider conformance contract; adapters must be tested to ensure every protected path invokes pre_action.

Durable cognitive effects

CognitiveAgentRuntimeV2 treats memory_mutation and tool as effectful. An adapter that advertises either operation must provide both an explicit CognitiveDurableOperationStoreV2 and a CognitiveEffectSinkV2; construction fails closed when either boundary is absent. The runtime never dispatches these operations through the adapter's general execute method.

Before dispatch, the durable store atomically reserves the tuple tenantId/sessionId/operationId, binds it to the complete request digest, and claims the expected session revision. The sink receives a stable idempotency key and request digest. Its apply implementation must atomically deduplicate that pair, while lookup must return the durable sink receipt/result for crash reconciliation. The store then atomically moves the operation from prepared to applied together with the session-state CAS. Replays return the recorded outcome, conflicting request digests fail, and a second operation cannot spend the same session revision. Durable operation records omit request payloads but retain the applied result and original outcome for exact replay, so production stores must encrypt and govern that output according to its data classification. A prepared record whose sink state cannot be established remains claimed and blocks that session revision; operators must reconcile it rather than deleting the reservation and risking a duplicate effect.

This protocol prevents duplicate logical application only when the configured sink honors its idempotency contract. It does not claim exactly-once delivery to an arbitrary external system: integrations must use an idempotent downstream API or durably reconcile their own receipt before reporting success. The in-memory store is intended for local execution and deterministic tests; a multi-process deployment must supply a transactional durable implementation.

Portable heterogeneous agents

@agentplat/runtime/adapter adds a stateful protocol for language, vision, action, policy, symbolic, hybrid and custom agents. A manifest declares the modalities, interaction modes, cancellation behavior and recovery support of one immutable adapter implementation. Applications negotiate those capabilities before opening a session, so incompatible peers fail before execution.

PortableAgentSessionRuntimeV1 binds every session to an adapter implementation, a versioned local control implementation and a revisioned role. Each step uses compare-and-set state, a stable idempotency key and explicit source zones for observations. Outputs and inert action proposals remain withheld until the configured control approves the relevant pre-step, post-output and pre-action checkpoints. Control errors fail closed.

Sessions can be paused, checkpointed, restored, assigned a successor role and closed. Adapters may implement the paired exportCheckpoint and importCheckpoint hooks to move portable application state between unused sessions bound to the exact same adapter version and implementation. Imports are digest-checked, pause before restore and are idempotent for the same transfer. Role updates must form an unbroken revision chain for the same objective. Ephemeral credentials are supplied only to the adapter call and are never persisted, exported or shown to controls.

Two bridges connect this protocol to the existing runtime:

  • createAgentRuntimePortableAdapterV1 exposes an existing AgentRuntime agent through the portable protocol without granting tool calls action authority.
  • createPortableAgentProviderV1 exposes a portable session as an AgentProvider, allowing workflows and collectives to use the controlled, stateful execution path through DefaultAgentRuntime.

版本与发布记录

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

版本发布日期距今
1.5.1latest2026/11/044 天前
1.5.02026/10/317 天前
1.4.02026/10/2315 天前
1.3.02026/10/1622 天前
1.2.02026/10/011 个月前
1.1.02026/09/301 个月前

其他发布通道:agentplat-stage-74c331e7b716 → 0.3.0-beta.3,agentplat-stage-dbd047c3c9a9 → 0.3.0-beta.4,agentplat-stage-ffca668731c9 → 0.3.0-beta.4,agentplat-stage-61ee591e79b0 → 0.3.0-beta.4,agentplat-stage-dc16b2267584 → 0.3.0-beta.5,agentplat-stage-e43ff308bc22 → 0.3.0-beta.6。

关于 @agentplat/runtime 的常见问题

@agentplat/runtime 是什么?

Provider-neutral executable agent runtime for AgentPlat.

如何安装 @agentplat/runtime?

在项目目录运行 npm install @agentplat/runtime,或使用 pnpm add / yarn add / bun add。

@agentplat/runtime 支持 TypeScript 吗?

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

@agentplat/runtime 支持 ESM 还是 CommonJS?

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

@agentplat/runtime 可以商用吗?

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

@agentplat/runtime 的下载量有多少?

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

@agentplat/runtime 还在维护吗?

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