@copilotkit/intelligence-mastra

中文文档
1.72.0发布于 2026/10/16MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4102

Learned skill delivery for Mastra agents through CopilotKit Intelligence

原始使用文档
文档目录4 节
  1. Setup
  2. Execution and resume
  3. Configuration
  4. Multiple containers

CopilotKit Intelligence skills for Mastra

Keep published skills from one or more Learning containers available to Mastra agents. The adapter adds a catalog and two native read tools. Each invocation uses one verified snapshot, including tool-first resumes.

Requires Node.js 22.13+ and Mastra core >=1.0.0 <2. The Intelligence server and canonical Runtime client must support the learned-snapshot API.

Setup

import { Agent } from "@mastra/core/agent";
import {
  SkillRegistry,
  createSkillRegistryProcessor,
} from "@copilotkit/intelligence-mastra";

// Set CPK_INTELLIGENCE_API_KEY and CPK_INTELLIGENCE_LEARNING_CONTAINER_ID.
// Set INTELLIGENCE_API_URL for a self-hosted Intelligence server.
const registry = new SkillRegistry();
await registry.initialize();
const skills = createSkillRegistryProcessor({ registry });
const agent = skills.wrapAgent(
  new Agent({
    id: "support",
    name: "Support",
    model: "openai/gpt-4.1",
    instructions: "Follow our support policy.",
    inputProcessors: [skills],
    tools: { ...skills.tools },
  }),
);

const result = await agent.generate("Help with a refund.");

Register other processors and tools in the same native arrays and maps. Reserve copilotkit_load_skill and copilotkit_read_skill_file for this adapter. Both tools remain available for an empty registry. Host instructions retain precedence over learned content.

Execution and resume

Call the wrapped Agent for generate, stream, resumeGenerate, and resumeStream. The wrapper also covers the native approval helpers: approveToolCall, declineToolCall, approveToolCallGenerate, and declineToolCallGenerate where the installed Mastra version provides them.

Each call acquires its snapshot before native execution. Streaming results retain Mastra's native shape. A resume starts a new invocation and captures the current snapshot. Private async context carries that snapshot, so restored tools cannot read an older snapshot from a suspended closure. Snapshots are not stored in request context or processor state.

Pass abortSignal in the invocation options to cancel the delivery wait and native execution. A signal supplied only through Agent defaultOptions takes effect during native execution and cannot cancel the preceding delivery wait. Cancelling one caller does not cancel a registry refresh shared with other callers. Register and wrap each selected agent explicitly; subagent propagation follows Mastra. Agent networks, legacy methods, background workers, and separate durable-worker dispatch are outside this adapter's supported entry points.

Configuration

Pass an application-owned CopilotKitIntelligence client from @copilotkit/runtime/v2 to new SkillRegistry({ client, containerId }) to reuse its credentials and HTTP transport. Explicit configuration overrides environment values. An injected client is authoritative for connection configuration.

freshnessWindowMs and requestTimeoutMs default to 5000. debug defaults to false. Set revision or CPK_INTELLIGENCE_SKILLS_REVISION for an exact whole-container pin. Explicit initialization is optional; the first wrapped invocation can initialize the registry.

Catch SkillDeliveryError during initialization or invocation. Its stable code describes the failure. Warm transient errors retain the previous verified snapshot; confirmed denial blocks new invocations. registry.status exposes initialization, revision, mode, freshness, and safe error status.

The adapter reads skills in memory and does not write files or execute scripts. The model chooses whether to load or follow skills. The package uses the canonical Runtime client and retains that client's dependency footprint; it does not depend on the LangGraph adapter.

See the learned skill delivery guide for server requirements and migration from CLI downloads.

Multiple containers

Use the same registry with an explicit list:

const registry = new SkillRegistry({
  containers: [
    { id: "support", revision: "revision-123" },
    { id: "company-wide" },
  ],
});

Each entry follows latest unless it has a revision pin. IDs must be unique and nonempty. The SDK rejects an empty list or a list combined with containerId or top-level revision. TypeScript rejects mixed forms at compile time too. The old interface remains supported. An explicit list ignores legacy container and revision environment variables. Credentials, freshness, and timeouts remain shared.

The new interface uses names such as support/refund-policy in the catalog and tool calls. The prefix URI-encodes the container ID, so names cannot collide between containers. The old interface keeps unprefixed Skill names.

Each container keeps its own cache and revision. Every invocation captures the full combined catalog. A cold failure or confirmed denial from any container blocks the invocation. Existing transient-error fallback applies separately to each warm container. registry.status.containers lists per-container status and revision. Aggregate status has no revision pin.

Explicit containers accepts 1–50 unique container IDs and sends one batch request for all sources that need a refresh. This also applies to a list with one entry. The server must support POST /api/v1/learning/skills/batch before you use this configuration. The SDK does not fall back to separate requests. Legacy containerId configuration keeps its existing single-container request. Both interfaces use the same authentication configuration.

版本与发布记录

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

版本发布日期距今
1.72.0latest2026/10/1625 天前
1.71.22026/09/151 个月前
0.1.02026/09/151 个月前

关于 @copilotkit/intelligence-mastra 的常见问题

@copilotkit/intelligence-mastra 是什么?

Learned skill delivery for Mastra agents through CopilotKit Intelligence

如何安装 @copilotkit/intelligence-mastra?

在项目目录运行 npm install @copilotkit/intelligence-mastra,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^3.25.76 || ^4.0.0)、@mastra/core(>=1.0.0 <2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@copilotkit/intelligence-mastra 支持 TypeScript 吗?

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

@copilotkit/intelligence-mastra 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@copilotkit/intelligence-mastra 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@copilotkit/intelligence-mastra 可以商用吗?

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

@copilotkit/intelligence-mastra 的下载量有多少?

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

@copilotkit/intelligence-mastra 还在维护吗?

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