@cef-ai/agent-sdk

中文文档
5.12.1发布于 2026/10/29TypeScriptES Module零依赖近 30 天下载 3213

Author agents for the Cere Execution Fabric: a small surface of decorators and types that maps directly to the runtime contract.

原始使用文档
文档目录7 节
  1. Install
  2. Quickstart
  3. API summary
  4. How it runs (runtime model)
  5. Subpath exports
  6. Companion packages
  7. References

@cef-ai/agent-sdk

Author agents for the Cere Execution Fabric: a small surface of decorators and types that maps directly to the runtime contract.

Install

pnpm add @cef-ai/agent-sdk

For tests, also install the harness:

pnpm add -D @cef-ai/testing

Quickstart

An agent is a default-exported class with decorated methods. @OnEvent binds an event type to a handler; @OnStart and @OnClose are lifecycle hooks. Context is the single object the runtime threads through every call.

import {
  OnClose,
  OnEvent,
  OnStart,
  type Context,
  type Event,
  type OnCloseReason,
} from "@cef-ai/agent-sdk";

interface UserMessage {
  text: string;
}

export default class Echo {
  @OnStart
  async onStart() {
    // Logging + HTTP are plain Web globals, not ctx members:
    console.info("started");
  }

  @OnEvent("user_message")
  async onMessage(event: Event<UserMessage>, ctx: Context) {
    await ctx
      .cubby("history")
      .exec("INSERT INTO messages(text, ts) VALUES (?, ?)", [
        event.payload.text,
        Date.now(),
      ]);
    await ctx.publish("ack", { for: event.eventId });
  }

  @OnClose
  async onClose(_ctx: Context, reason: OnCloseReason) {
    console.info("closing", { reason });
  }
}

ctx carries only the CEF-specific platform calls. For plain capabilities, use the sandbox globals directly: console.* for logging (the runtime captures it) and fetch for HTTP.

Pair the class with a cef.config.ts:

import { defineAgent } from "@cef-ai/agent-sdk/config";

export default defineAgent({
  id: "echo",
  version: "1.0.0",
  entry: "./agent.ts",
  cubbies: [{ alias: "history", migrations: "./migrations/history" }],
});

API summary

KindSymbolNotes
Decorator@OnEvent(type)Bind an event type (string literal) to a handler.
Decorator@OnStartMark the start lifecycle hook.
Decorator@OnCloseMark the close lifecycle hook.
TypeContextCEF-specific platform calls only — cubby, models, publish, settings, close. (Log/HTTP are the globals console / fetch.)
TypeEvent<P>{ id, type, ts, from, payload: P }.
TypeCubbyHandlequery(sql, params) / exec(sql, params) over per-alias storage.
TypeModelHandle<I,O>infer(input) / stream(input) per declared model alias.
TypeOnCloseReason"revoked" | "idle_timeout" | "closed_by_agent" | "failed".
InterfaceKnownEventTypesDeclaration-merged event-type map populated by typegen.
FunctiondefineAgent(config)Identity helper that preserves literal types of AgentConfig.
TypeAgentConfigTop-level config: id, version, entry, cubbies, models, settings, fetch, publishes, lifecycle.

How it runs (runtime model)

Per Agent Runtime ADR-001, the Cere Network runtime is a CEF-agnostic bundle executor: it exposes only Web-platform globals (fetch, console, URL, crypto, TextEncoder, timers, …) plus one opaque globalThis.context object, and dispatches invocations as globalThis.__handlers[name](event, context).

ctx is CEF-specific add-ons only — SDK code compiled into your bundle by cef build, not a runtime-provided binding:

  • ctx.publish / ctx.cubby / ctx.models[…].infer / ctx.close → fetch calls to the endpoints the orchestrator places in globalThis.context (context.endpoints.*, with context.auth headers).
  • ctx.settings → context.settings.

Plain Web-platform capabilities are not mirrored on ctx — use the sandbox globals directly: console.* for logging (captured out-of-band by the runtime) and fetch for HTTP.

You never write the shim code — you author the decorated class, and the shims (the @cef-ai/agent-sdk/runtime subpath) are bundled in automatically.

Inference usage is reported automatically. Each ctx.models[…].infer call captures the gateway's usage and the SDK folds a _modelCalls array into your handler's return value; the orchestrator reads it to record per-model token/GPU usage (ADR-004). _modelCalls is a reserved result key — don't set it yourself.

Subpath exports

SpecifierPurpose
@cef-ai/agent-sdkDecorators, Context, Event, KnownEventTypes, ModelHandle, CubbyHandle, OnCloseReason.
@cef-ai/agent-sdk/configdefineAgent and the AgentConfig shape — used in cef.config.ts.
@cef-ai/agent-sdk/runtimeBuild-internal: the ctx shims + registerHandlers that cef build compiles into the bundle. Authors never import this directly.

For testing, use @cef-ai/testing directly — import { testAgent } from "@cef-ai/testing".

Companion packages

  • @cef-ai/cli — cef build (esbuild + manifest), cef typegen (populates KnownEventTypes), cef inspect.
  • @cef-ai/testing — simulator harness for unit and integration tests.
  • @cef-ai/eslint-plugin — editor-time lints mirroring the build-time checks.

References

  • Agent SDK spec: ../../../company-memory-bank/specs/platform/03-components/agent-sdk.md
  • Runtime integration contract: ../../../company-memory-bank/specs/platform/03-components/sdk-runtime-integration-contract.md
  • Implementation plan: ../../../company-memory-bank/plans/2026-04-27-sdk-implementation-plan.md

The ../company-memory-bank/... paths are local references to an internal sibling repo and are not browsable from a fresh clone.

版本与发布记录

@cef-ai/agent-sdk 共发布 27 个版本,首次发布于 2026/04/30;过去 12 个月发布了 27 个版本。

版本发布日期距今
5.12.1latest2026/10/2911 天前
5.12.02026/10/2218 天前
5.11.02026/10/2119 天前
5.10.02026/10/1723 天前
5.9.02026/10/1623 天前
5.8.02026/10/081 个月前

关于 @cef-ai/agent-sdk 的常见问题

@cef-ai/agent-sdk 是什么?

Author agents for the Cere Execution Fabric: a small surface of decorators and types that maps directly to the runtime contract.

如何安装 @cef-ai/agent-sdk?

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

@cef-ai/agent-sdk 支持 TypeScript 吗?

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

@cef-ai/agent-sdk 支持 ESM 还是 CommonJS?

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

@cef-ai/agent-sdk 可以商用吗?

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

@cef-ai/agent-sdk 的下载量有多少?

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

@cef-ai/agent-sdk 还在维护吗?

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