@alvin0/ai-agent-sdk-core

中文文档
0.1.16发布于 2026/11/06MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2829

Universal contracts and runtime primitives for ai-agent-sdk

原始使用文档

@alvin0/ai-agent-sdk-core

Provider-neutral contracts and runtime primitives for building model adapters and streaming AI applications.

Runtime: Universal. Published code uses ECMAScript, Fetch-compatible types, Web Streams, AbortController, performance timing, and Web Crypto. It does not use Node built-ins, process, Buffer, local paths, filesystem access, child processes, or stdio.

pnpm add @alvin0/ai-agent-sdk-core

createAgentRuntime() is the recommended composition root. defineAgent() captures a reusable agent definition, and every runtime exposes an SdkLogger whose records share runtime/run correlation and privacy policy:

import {
  createAgentRuntime,
  defineAgent,
  type SdkLogger,
} from '@alvin0/ai-agent-sdk-core'

const runtime = await createAgentRuntime({ providers: [provider] })
const definition = defineAgent({ id: 'assistant', instructions: 'Be concise.' })
const logger: SdkLogger = runtime.logger({ fields: { component: 'assistant' } })
const agent = runtime.agent({ ...definition, model: { provider: 'openai', id: 'gpt-6-luna' } })
logger.info('agent ready')
import { ModelAdapter, ModelRegistry } from '@alvin0/ai-agent-sdk-core'

const registry = new ModelRegistry()
registry.registerAdapter(['example'], new YourAdapter())

const call = registry.stream({
  provider: 'example',
  model: 'model-id',
  messages: [],
})

for await (const chunk of call) {
  // Consume normalized chunks.
}

const report = await call.report

The package includes message and stream contracts, model registry and retry primitives, normalized errors, usage accounting, explicit observation/correlation ports, and transactional provider-plugin registration. Provider HTTP/SSE transport, concrete exporters, filesystem skills, environment credentials, and protocol implementations belong to separate capability packages.

The documented root plus /agent, /memory, /observability, /provider, /skills, /tools, /embedding, and ./package.json are public. Internal source paths are not compatibility contracts.

Session hooks.beforeCompletion may return { kind: 'continue', messages: [...] } to finish pending application work after a model stops voluntarily. Use createUserMessage with source: { kind: 'app', producer: 'your-workflow' }. The SDK consumes this context inside the same turn and run, preserving usage, remaining budgets, cancellation, and raw history. Continuation is ignored when capacity is exhausted. This hook runs before empty-answer recovery, so it can continue a model that stopped after commentary without a final answer. Every message must be app-sourced; a mixed or human-sourced batch is rejected atomically. An empty batch does not itself continue the turn. Hosts should bound repeated completion objections and stop when the workflow no longer makes progress. { kind: 'yield' } still pauses without a final completion or deep-mode polling. onTurnEnd retains its recovered-outcome semantics and also accepts continuation decisions; application completion gates should prefer beforeCompletion.

validateJsonFileContent from /tools or /agent validates complete .json write/edit content before a host writes it. Validation defaults on, preserves accepted bytes and reports recoverable syntax errors. See workspace JSON writes for host opt-out and integration examples.

createManagedAgentTeam from /agent supports lead delegation and opt-in shared-board collaboration. See the multi-agent host guide for tools, budgets and migration from 0.1.12, and the offline example for both modes without provider credentials.

Opt-in optimization helpers added in 0.1.5 include defineActionFusion and createModelEvidenceReducer from /tools, and createContextOptimizer from /memory. Applications select pipeline steps, milestone summaries, log storage, and reducer models. See the application guide for configuration, exact-evidence fallback, and runnable validation.

Existing agent, tool, and session imports remain available. Review the upgrade guide for narration defaults, queued steering receipts, and managed-team validation changes after the published 0.1.4 release. Program tools additionally require session-level experimentalPrograms grants; ordinary tools do not.

For 0.1.7 completion, pending input, stream replacement and Stop behavior, see the upgrade guide. RuntimeAgentSession.hasUnansweredInput() and runPending() expose work left after a terminal round. Use response.completed for objective completion.

In 0.1.8, the exact-repeat guard can reuse the immediately preceding successful tool result and allow one bounded model replan. EmbeddingError.failure preserves available provider HTTP status, retry delay and request id through normalization. See upgrading from 0.1.7 for exclusions, cancellation and budget behavior.

版本与发布记录

@alvin0/ai-agent-sdk-core 共发布 17 个版本,首次发布于 2026/09/10;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.16latest2026/11/061 天前
0.1.152026/11/025 天前
0.1.142026/10/2117 天前
0.1.132026/10/1721 天前
0.1.122026/10/1127 天前
0.1.112026/10/1028 天前

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

@alvin0/ai-agent-sdk-core 是什么?

Universal contracts and runtime primitives for ai-agent-sdk

如何安装 @alvin0/ai-agent-sdk-core?

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

@alvin0/ai-agent-sdk-core 支持 TypeScript 吗?

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

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

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

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

@alvin0/ai-agent-sdk-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

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

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

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

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