agentkit-core
v0.1.0
Published
Universal AI agent middleware — Make any website agent-ready. Implements Cloudflare Agentic Web standards: Markdown Negotiation, Content Signals, API Catalog, auth.md, A2A Agent Card, MCP Server Card, OAuth Discovery, Web Bot Auth, DNS-AID, and more.
Maintainers
Readme
agentkit-core
通用 AI Agent 中间件
让任何网站立即支持 AI 代理。一个包,适配所有框架。
agentkit-core 是一个零依赖的通用中间件,在单个包中实现了 所有 Cloudflare Agentic Web 标准。将其添加到任何 Node.js、Edge、Deno 或 Bun 框架中,您的网站将立即可被 AI 代理发现、读取和互操作。
功能特性
| 类别 | 标准 | 端点 |
|------|------|------|
| 🤖 快速启用 | 带 AI 规则的 robots.txt | /robots.txt |
| 📊 内容信号 | 机器可读的内容政策 | HTTP Content-Signal 请求头 |
| 📝 Markdown 协商 | 为代理提供 HTML→Markdown | Accept: text/markdown |
| 🗺️ 网站地图 | 代理友好的 XML 网站地图 | /sitemap.xml |
| 📚 API 目录 | RFC 9727 API 发现 | /.well-known/api-catalog |
| 🔗 Link 请求头 | 自动注入发现链接 | HTTP Link: 请求头 |
| 🔐 auth.md | AI 机器人登录说明 | /auth.md |
| 🃏 A2A Agent 卡片 | Agent-to-Agent 发现 | /.well-known/agent-card.json |
| 🛠️ MCP 服务器卡片 | 模型上下文协议 | /.well-known/mcp/server-card.json |
| 💡 技能索引 | 已发布的代理技能 | /.well-known/agent-skills/index.json |
| 🔑 OAuth 发现 | RFC 8414 + RFC 9728 | /.well-known/oauth-authorization-server |
| 🛡️ Web 机器人认证 | HTTP 消息签名 | /.well-known/http-message-signatures-directory |
| 🌐 DNS-AID | 基于 DNS 的代理发现 | DNS TXT 记录生成器 |
| 📄 llms.txt | 为 LLM 优化的内容索引 | /llms.txt |
| 💳 Commerce 存根 | ACP, AP2, MPP, UCP, x402 | /.well-known/{protocol} |
安装
npm install agentkit-core
# 或
pnpm add agentkit-core
# 或
yarn add agentkit-core快速开始
Express
import express from 'express';
import { agentKit } from 'agentkit-core/express';
const app = express();
app.use(agentKit({
baseUrl: 'https://example.com',
// 带 AI 感知规则的 robots.txt
robots: {
rules: [
{ userAgent: '*', allow: ['/'] },
{ userAgent: ['GPTBot', 'CCBot'], disallow: ['/'] },
],
sitemap: 'https://example.com/sitemap.xml',
},
// 声明内容政策
contentSignals: {
aiTrain: 'no',
search: 'yes',
aiInput: 'yes',
},
// 向 AI 代理提供干净的 Markdown
markdown: { enabled: true },
// A2A Agent 卡片
agentCard: {
name: '示例代理',
description: 'example.com 的 AI 代理',
version: '1.0.0',
url: 'https://example.com',
capabilities: { streaming: true },
},
// auth.md — 机器人如何进行身份验证
authMd: {
serviceName: 'Example',
resourceServer: 'https://example.com',
registrationFlow: 'agent-verified',
},
// 在首页自动注入 Link: 请求头
linkHeaders: true,
}));
app.listen(3000);Hono (Cloudflare Workers / Edge)
import { Hono } from 'hono';
import { agentKit } from 'agentkit-core/hono';
const app = new Hono();
app.use('*', agentKit({
baseUrl: 'https://example.com',
robots: { rules: [{ userAgent: '*', allow: ['/'] }] },
contentSignals: { aiTrain: 'no', search: 'yes' },
markdown: { enabled: true },
}));
export default app;Next.js
// middleware.ts
import { createAgentKitMiddleware } from 'agentkit-core/nextjs';
export const middleware = createAgentKitMiddleware({
baseUrl: 'https://example.com',
contentSignals: { aiTrain: 'no', search: 'yes', aiInput: 'yes' },
markdown: { enabled: true },
linkHeaders: true,
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};Cloudflare Workers
import { agentKit } from 'agentkit-core/cloudflare';
const kit = agentKit({
baseUrl: 'https://example.com',
contentSignals: { aiTrain: 'no', search: 'yes' },
markdown: { enabled: true },
});
export default {
fetch: kit.fetch(async (req, env, ctx) => {
return new Response('你好,世界!');
}),
};Deno / Bun
import { agentKit } from 'agentkit-core/generic';
const kit = agentKit({
baseUrl: 'https://example.com',
robots: { rules: [{ userAgent: '*', allow: ['/'] }] },
contentSignals: { aiTrain: 'no', search: 'yes' },
});
// Deno
Deno.serve(kit.handler(async (req) => new Response('你好!')));
// Bun
Bun.serve({ fetch: kit.handler(async (req) => new Response('你好!')) });性能
agentkit-core 以零开销为设计原则:
- O(1) 路由查找 — 使用
Map而非正则表达式数组 - 零运行时依赖 — 无需安装额外依赖,无兼容性风险
- 静态响应 — 所有响应在启动时计算,而非每次请求时
- Tree-shakeable — 仅导入您使用的功能
- Edge 优先 — 原生支持 Cloudflare Workers、Deno Deploy、Vercel Edge
标准与参考
| 标准 | 描述 | RFC/规范 |
|------|------|----------|
| Content-Signal | 内容使用政策请求头 | Cloudflare |
| Markdown 协商 | Accept: text/markdown | Cloudflare |
| API 目录 | Well-known API 目录 | RFC 9727 |
| auth.md | 代理认证指南 | workos/auth.md |
| A2A Agent 卡片 | Agent-to-Agent 协议 | google/A2A |
| MCP 服务器卡片 | 模型上下文协议 | Anthropic MCP |
| OAuth 发现 | 授权服务器元数据 | RFC 8414 |
| 受保护资源 | OAuth 受保护资源元数据 | RFC 9728 |
| Web 机器人认证 | HTTP 消息签名 | RFC 9421 |
| DNS-AID | AI 发现的 DNS | IETF 草案 |
| llms.txt | 为 LLM 优化的内容索引 | llmstxt.org |
| robots.txt | 机器人访问控制 | RFC 9309 |
许可证
MIT © 2026
