npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

agentkits

v2.0.3

Published

Agent Model Layer — One-line LLM access with built-in memory. 29 providers, 18 embeddings, zero lock-in.

Downloads

843

Readme

🧰 AgentKits

多模型 AI 智能体工具库

npm version License TypeScript

一个接口调用所有大模型 · 20 个 LLM · 15 个向量化引擎 · 38 个功能模块


✨ 项目简介

AgentKits 是面向 AI 智能体开发者的 TypeScript 工具库。通过统一接口,你可以无缝切换 20+ 个大模型供应商和 15+ 个向量化引擎,无需修改业务代码。

🇨🇳 为中国 AI 开发者而生

AgentKits 原生支持中国主流大模型,不是后期适配,而是一等公民:

  • DeepSeek 深度求索 — DeepSeek-V3、R1 推理模型
  • DashScope 通义千问 — Qwen-Max/Plus/Turbo,阿里云大模型
  • Zhipu 智谱AI — GLM-4、GLM-4V 多模态
  • Moonshot 月之暗面 — Kimi 长上下文模型
  • Yi 零一万物 — Yi-Large 系列
  • Baichuan 百川智能 — Baichuan-4
  • SiliconFlow 硅基流动 — 多模型聚合平台
  • StepFun 阶跃星辰 — Step-2 系列
  • MiniMax — abab6.5s

💡 中国模型支持:AgentKits 深度集成 9 个中国大模型供应商,覆盖对话、向量化、函数调用、流式输出全场景。


🚀 快速开始

npm install agentkits

对话补全

import { createChat } from 'agentkits';

// 使用深度求索
const chat = createChat({ provider: 'deepseek', model: 'deepseek-chat' });
const reply = await chat.complete('什么是 AI Agent?');
console.log(reply);

// 切换到通义千问,只需改 provider
const qwen = createChat({ provider: 'dashscope', model: 'qwen-max' });
const reply2 = await qwen.complete('解释 RAG 检索增强生成');

流式输出

import { createChat } from 'agentkits';

const chat = createChat({ provider: 'zhipu' });  // 智谱AI

// 流式输出,实时打印
for await (const chunk of chat.stream('从1数到10')) {
  process.stdout.write(chunk.content);
}

向量化

import { createEmbedding } from 'agentkits';

// 通义千问向量化
const emb = createEmbedding({ provider: 'dashscope' });
const vector = await emb.embed('语义搜索');

// 批量向量化
const vectors = await emb.embedBatch(['文档一', '文档二', '文档三']);

函数调用

import { createToolChat, defineTool } from 'agentkits';

const weather = defineTool({
  name: 'get_weather',
  description: '获取城市天气',
  parameters: {
    type: 'object',
    properties: { city: { type: 'string', description: '城市名' } },
    required: ['city'],
  },
  handler: async ({ city }) => `${city}:晴天,25°C`,
});

const chat = createToolChat({ provider: 'deepseek', tools: [weather] });
const result = await chat.run('北京今天天气怎么样?');

RAG 检索增强生成

import { createRAG } from 'agentkits';

const rag = createRAG({
  embeddingProvider: 'dashscope',  // 通义千问做向量化
  llmProvider: 'deepseek',         // 深度求索做生成
  topK: 3,
  chunkSize: 300,
});

// 导入文档
await rag.ingest(['AgentKits 是面向 AI 智能体的工具库...', '支持 20 个大模型供应商...']);

// 查询
const result = await rag.query('AgentKits 支持哪些供应商?');
console.log(result.answer);

故障转移

import { createChatWithFailover } from 'agentkits';

// 主路径走 DeepSeek,失败自动切换到通义千问,再到 Gemini
const chat = createChatWithFailover({
  providers: [
    { provider: 'deepseek' },
    { provider: 'dashscope' },
    { provider: 'gemini' },
  ],
  onFailover: (from, to, err) => console.log(`故障转移:${from} → ${to}`),
});

工作流引擎

import { createWorkflow } from 'agentkits';

const workflow = createWorkflow({
  name: '研究管线',
  startStep: 'search',
  steps: [
    {
      id: 'search', type: 'tool',
      tool: { name: 'search', handler: async (input) => await searchWeb(input.query) },
      input: (ctx) => ({ query: ctx.variables.topic }),
      output: 'searchResults', next: 'summarize',
    },
    {
      id: 'summarize', type: 'llm',
      llm: { provider: 'deepseek', prompt: '总结以下内容:{{searchResults}}' },
      output: 'summary',
    },
  ],
});

MCP 客户端

import { createMCPClient } from 'agentkits';

const mcp = await createMCPClient({ serverUrl: 'http://localhost:3001/sse' });
const tools = await mcp.listTools();                    // 获取工具列表
const funcDefs = await mcp.toFunctionDefs();            // 转换为 OpenAI 格式
const result = await mcp.callTool('search', { query: '你好' });  // 调用工具

A2A 协议(智能体间通信)

import { createA2AClient } from 'agentkits';

const client = createA2AClient({ baseUrl: 'http://localhost:8080' });
const card = await client.getAgentCard();
const task = await client.sendTask({
  id: 'task-1',
  message: { role: 'user', parts: [{ type: 'text', text: '研究 AI 趋势' }] },
});

📋 大模型供应商 (20)

| 供应商 | 中文名 | 模型 | 流式输出 | 函数调用 | 视觉理解 | |--------|--------|------|---------|---------|---------| | OpenAI | — | GPT-4o, GPT-4o-mini, o1, o3 | ✅ | ✅ | ✅ | | Gemini | — | Gemini 2.0/1.5 Pro/Flash | ✅ | ✅ | ✅ | | DeepSeek | 深度求索 | DeepSeek-V3, R1 | ✅ | ✅ | ❌ | | DashScope | 通义千问 | Qwen-Max/Plus/Turbo | ✅ | ✅ | ✅ | | Zhipu | 智谱AI | GLM-4, GLM-4V | ✅ | ✅ | ✅ | | Moonshot | 月之暗面 | Kimi (moonshot-v1) | ✅ | ✅ | ❌ | | Yi | 零一万物 | Yi-Large | ✅ | ✅ | ❌ | | Baichuan | 百川智能 | Baichuan-4 | ✅ | ✅ | ❌ | | SiliconFlow | 硅基流动 | 多模型聚合 | ✅ | ✅ | ❌ | | StepFun | 阶跃星辰 | Step-2 | ✅ | ✅ | ❌ | | MiniMax | MiniMax | abab6.5s | ✅ | ✅ | ❌ | | Grok | — | grok-2 | ✅ | ✅ | ❌ | | Cohere | — | Command R+ | ✅ | ✅ | ❌ | | Fireworks | — | FireFunction, Mixtral | ✅ | ✅ | ❌ | | Together | — | Llama, Mixtral | ✅ | ✅ | ❌ | | Groq | — | Llama, Mixtral | ✅ | ✅ | ❌ | | Perplexity | — | Sonar | ✅ | ❌ | ❌ | | Ollama | 本地部署 | 任意本地模型 | ✅ | ✅ | ✅ | | Custom | 自定义 | 任意 OpenAI 兼容 | ✅ | ✅ | ✅ |

📐 向量化引擎 (15)

| 供应商 | 中文名 | 模型 | 维度 | |--------|--------|------|------| | OpenAI | — | text-embedding-3-small/large | 256–3072 | | Gemini | — | text-embedding-004 | 768 | | DashScope | 通义千问 | text-embedding-v3 | 1024 | | DeepSeek | 深度求索 | (兼容接口) | 可变 | | Zhipu | 智谱AI | embedding-3 | 2048 | | SiliconFlow | 硅基流动 | 多模型 | 可变 | | Cohere | — | embed-v3 | 1024 | | Jina | — | jina-embeddings-v3 | 1024 | | Voyage | — | voyage-3 | 1024 | | Mixedbread | — | mxbai-embed-large | 1024 | | Nomic | — | nomic-embed-text | 768 | | Fireworks | — | nomic, thenlper | 可变 | | Together | — | 多模型 | 可变 | | Ollama | 本地部署 | 任意本地模型 | 可变 | | Custom | 自定义 | 任意兼容接口 | 可变 |


📦 模块目录 (38)

核心模块

| 模块 | 引入路径 | 说明 | |------|---------|------| | 大模型对话 | agentkits/llm | 统一对话补全接口,支持 20 个供应商 | | 向量化 | agentkits/embedding | 统一向量化接口,支持 15 个引擎 | | 流式输出 | agentkits/streaming | SSE 解析、流组合、中断控制 | | 结构化输出 | agentkits/structured | JSON Schema 校验的大模型输出 | | 函数调用 | agentkits/function-calling | 跨供应商函数/工具调用格式转换 |

智能体构建

| 模块 | 引入路径 | 说明 | |------|---------|------| | Agent 循环 | agentkits/agent | ReAct 风格智能体,自动工具调用循环 | | 工具调用 | agentkits/tools | 定义和执行工具,适配任意大模型 | | 多轮对话 | agentkits/conversation | 多轮对话管理,滑动窗口 | | Agent 记忆 | agentkits/agent-memory | 短期/长期记忆,自动摘要 | | 提示词模板 | agentkits/prompt-template | Handlebars 风格模板引擎 | | 安全护栏 | agentkits/guardrails | 输入输出校验、内容过滤、PII 检测 |

RAG 检索增强生成

| 模块 | 引入路径 | 说明 | |------|---------|------| | RAG 管线 | agentkits/rag | 完整的检索-增强-生成管线 | | 重排序 | agentkits/rerank | API 重排序(Cohere、Jina 等) | | 本地重排 | agentkits/reranker | Cross-encoder 本地重排序 | | 网页搜索 | agentkits/web-search | Brave、Tavily、Serper、SearXNG | | PDF 解析 | agentkits/pdf-parser | PDF 文本提取与分块 | | 文本分块 | agentkits/chunker | 智能分块(固定、句子、递归、语义) |

多模态

| 模块 | 引入路径 | 说明 | |------|---------|------| | 视觉理解 | agentkits/vision | 跨供应商图像理解 | | 语音合成 | agentkits/tts | TTS(OpenAI、Azure、ElevenLabs) | | 语音识别 | agentkits/stt | 语音转文字 | | 图像生成 | agentkits/image | DALL-E、Stability 等 |

基础设施

| 模块 | 引入路径 | 说明 | |------|---------|------| | 故障转移 | agentkits/failover | 自动供应商切换与健康检测 | | 智能路由 | agentkits/router | 按成本、速度、能力路由 | | 模型路由 | agentkits/model-router | 高级路由:模型画像与规则引擎 | | 限流器 | agentkits/ratelimit | Token bucket 限流 | | 供应商限流 | agentkits/rate-limiter | 按供应商限流(内置默认值) | | 响应缓存 | agentkits/response-cache | LRU + TTL 缓存 | | 重试 | agentkits/retry | 指数退避 + 抖动 | | 成本计算 | agentkits/cost | 跨供应商定价对比 | | Token 计数 | agentkits/token-counter | 按模型精确计数 | | 代理服务器 | agentkits/proxy | OpenAI 兼容代理 | | 性能基准 | agentkits/benchmark | 延迟与吞吐量基准测试 | | 日志 | agentkits/logger | 结构化日志 | | 链路追踪 | agentkits/tracing | OpenTelemetry 兼容分布式追踪 | | 代码解释器 | agentkits/code-interpreter | 沙箱代码执行(JS、Python、Shell) |

协议与互操作

| 模块 | 引入路径 | 说明 | |------|---------|------| | MCP 客户端 | agentkits/mcp-client | 连接 MCP 服务器,工具定义自动转换 | | 工作流引擎 | agentkits/workflow | 多步骤工作流:分支、并行、重试 | | A2A 协议 | agentkits/a2a | Google A2A 智能体间通信 |


⌨️ 命令行工具

npx agentkits chat     [--provider P] [--model M]      # 交互式对话
npx agentkits embed    "文本" [--provider P]            # 生成向量
npx agentkits benchmark [--providers a,b,c] [--runs N]  # 供应商性能对比
npx agentkits test                                      # 测试已配置的供应商
npx agentkits cost                                      # 查看定价对比
npx agentkits serve    [--port N]                       # 启动 OpenAI 兼容代理
npx agentkits list                                      # 列出所有供应商
npx agentkits mcp connect <url>                         # 连接 MCP 服务器

🏗️ 架构

┌──────────────────────────────────────────────────────────┐
│                      你的应用                             │
├──────────────────────────────────────────────────────────┤
│  Agent 循环 │ 工作流引擎 │ RAG │ 工具调用 │ 多轮对话       │
├──────────────────────────────────────────────────────────┤
│  安全护栏 │ 记忆管理 │ 结构化输出 │ 提示词模板             │
├──────────────────────────────────────────────────────────┤
│  智能路由 │ 故障转移 │ 响应缓存 │ 限流器 │ 重试机制         │
├──────────────────────────────────────────────────────────┤
│  MCP 客户端 │ A2A 协议 │ 链路追踪 │ 结构化日志             │
├──────────────────────────────────────────────────────────┤
│                   统一供应商接口层                         │
│  ┌─────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐          │
│  │ 对话 │ │ 向量 │ │ 视觉 │ │ 语音 │ │ 图像 │ ...      │
│  └──┬──┘ └──┬───┘ └──┬───┘ └──┬───┘ └──┬───┘          │
├─────┼───────┼────────┼────────┼────────┼───────────────┤
│  DeepSeek · 通义千问 · 智谱 · 月之暗面 · OpenAI · Gemini  │
│  零一万物 · 百川 · 硅基流动 · 阶跃星辰 · MiniMax · Ollama  │
└──────────────────────────────────────────────────────────┘

🔑 环境变量

# 中国大模型供应商
DEEPSEEK_API_KEY=sk-...          # 深度求索
DASHSCOPE_API_KEY=sk-...         # 通义千问(阿里云)
ZHIPU_API_KEY=...                # 智谱AI
MOONSHOT_API_KEY=sk-...          # 月之暗面 (Kimi)
YI_API_KEY=...                   # 零一万物
BAICHUAN_API_KEY=...             # 百川智能
SILICONFLOW_API_KEY=...          # 硅基流动
STEPFUN_API_KEY=...              # 阶跃星辰
MINIMAX_API_KEY=...              # MiniMax

# 国际供应商
OPENAI_API_KEY=sk-...
GEMINI_API_KEY=AI...
GROQ_API_KEY=gsk_...
COHERE_API_KEY=...
JINA_API_KEY=jina_...

📄 开源协议

Apache-2.0 · Deepleaper 跃盟科技