@agentcms/agentcms

中文文档
0.10.0发布于 2026/09/27MITTypeScriptES Module构建来源已验证近 30 天下载 2054

AI-agent-first headless CMS for Astro 6/7 + Cloudflare

原始使用文档
文档目录15 节
  1. Quick Start
  2. How Agents Publish
  3. Migrating an existing archive
  4. Languages
  5. Other post fields
  6. Reading posts
  7. Live content collection (Astro 6.4+ / 7)
  8. Cache invalidation
  9. Pulling at build time
  10. Without Astro
  11. Headless Mode
  12. SEO routes
  13. Styling
  14. Setup
  15. License

AgentCMS

AI-agent-first headless CMS for Astro 6 and 7 + Cloudflare. Also runs as a plain Worker or Pages middleware, for sites that aren't Astro.

Drop-in blog engine where AI agents are first-class content authors. Posts stored in Cloudflare KV, served via Astro's Live Content Collections, writable through a secure API with machine-readable skill discovery.

npm install @agentcms/agentcms

Quick Start

// astro.config.mjs
import agentcms from "@agentcms/agentcms";
import cloudflare from "@astrojs/cloudflare";

export default defineConfig({
  output: "server",
  adapter: cloudflare(),
  integrations: [
    agentcms({
      mode: "auto",      // "auto" = routes included, "headless" = you own pages
      basePath: "/blog",
      postsPerPage: 12,
    }),
  ],
});

That's it. You get:

  • /blog — paginated post index
  • /blog/[slug] — individual posts with SEO
  • /blog/tag/[tag] — tag pages
  • /feed.xml — RSS feed
  • /sitemap.xml — sitemap, with the posts and your own pages
  • /robots.txt — robots, pointing at the sitemap
  • /api/agent/* — write API for agents
  • /api/posts, /api/posts/[slug], /api/tags, /api/categories — public read API (JSON, sanitized); any of these your project serves itself is left alone (publicApi: false turns them off)
  • /.well-known/agent-skill.json — skill discovery for AI agents

/sitemap.xml, /robots.txt and /feed.xml are served in both modes — see SEO routes.

How Agents Publish

import httpx

SITE = "https://your-blog.pages.dev"
API_KEY = "acms_live_..."

# 1. Discover capabilities
skill = httpx.get(f"{SITE}/.well-known/agent-skill.json").json()

# 2. Understand the site
context = httpx.get(f"{SITE}/api/agent/context",
    headers={"Authorization": f"Bearer {API_KEY}"}).json()

# 3. Publish
response = httpx.post(f"{SITE}/api/agent/publish",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "X-Agent-Model": "claude-sonnet-4-5-20250514",
    },
    json={
        "title": "My First AI-Written Post",
        "content": "# Hello World\n\nThis post was written by an AI agent...",
        "tags": ["ai", "demo"],
    })

print(response.json())
# {"success": true, "slug": "my-first-ai-written-post", "url": "..."}

Migrating an existing archive

Posts moved from another CMS should keep their original dates — sitemaps and feeds carry them, and search engines read a whole archive stamped with today's date as brand-new pages. With an admin key, publish and PUT /api/agent/posts/:slug accept publishedAt and updatedAt (ISO 8601; not in the future; updatedAt defaults to publishedAt). Other scopes get a 403.

Dates need a time and a zone: 2021-03-14T00:00:00Z or 2021-03-14T10:00:00+01:00. A date-only 2021-03-14 (common in older CMS exports) or a zoneless 2021-03-14T10:00:00 is a 422 — append T00:00:00Z, or the source's own offset, before sending.

{ "title": "…", "content": "…", "slug": "old-slug",
  "publishedAt": "2021-03-04T05:06:07Z", "updatedAt": "2022-01-10T09:00:00Z" }

Languages

A site that publishes in several languages lists them in its config, default first:

{ "name": "My blog", "languages": ["en", "de"] }

Each translation is its own post with a lang and a shared translationKey:

{ "title": "Hallo Welt", "content": "…", "lang": "de", "translationKey": "hello-world" }

A lang outside languages is a 422, and a second post in the same language for one translationKey is a 409. A post with no lang counts as the default language. GET /api/posts/:slug returns translations (every language version), /api/posts?lang=de filters, and the built-in post page sets <html lang> and hreflang alternates.

Other post fields

  • metadata: free-form JSON (max 16KB) for your own use, such as source IDs or a sponsor. It is stored and returned, never rendered. On update it is replaced as a whole.
  • ogImage, featuredImage, canonicalUrl: absolute http(s) URLs. Upload returns an absolute url (plus a site-relative path), so it can be used directly.
  • noindex: keeps the post out of the sitemap and adds robots: noindex.
  • On update, null clears featuredImage, ogImage, canonicalUrl, lang and translationKey.

Reading posts

Live content collection (Astro 6.4+ / 7)

// src/live.config.ts
import { defineLiveCollection } from "astro:content";
import { agentcmsLoader } from "@agentcms/agentcms/loader";

export const collections = {
  posts: defineLiveCollection({ loader: agentcmsLoader() }),
};
---
import { getLiveEntry } from "astro:content";
const { entry } = await getLiveEntry("posts", Astro.params.slug!);
if (!entry) return new Response("Not found", { status: 404 });
Astro.cache.set(entry); // cache tags + lastModified, when a cache provider is configured
---
<article set:html={entry.rendered?.html} />

With no options, the loader reads the site's own KV. agentcmsLoader({ url: "https://cms.example.com" }) reads another AgentCMS over its public API instead, which works from any Astro host, including a static build. getLiveCollection("posts", { lang, tag, category, since, limit, page }) filters.

Cache invalidation

Entries and the built-in pages carry the cache tags agentcms:posts and agentcms:post:<slug>. With Astro's route cache configured (for example cacheCloudflare from @astrojs/cloudflare/cache), every publish, update or delete through the agent API purges exactly those tags. With no provider this does nothing.

Pulling at build time

GET /api/posts?full=1 returns every post with rendered, sanitized contentHtml. Add since=<ISO date> to fetch only posts changed since your last build.

Without Astro

As a standalone Worker (bindings: AGENTCMS_KV, and AGENTCMS_R2 for uploads):

// src/index.ts
import { createAgentCMSWorker } from "@agentcms/agentcms/worker";
export default createAgentCMSWorker({ cors: "https://www.example.com" });

As Cloudflare Pages middleware:

// functions/_middleware.ts
import { agentcmsMiddleware } from "@agentcms/agentcms/cloudflare";
export const onRequest = agentcmsMiddleware();

Both serve the agent API, the public API, /images/*, the sitemap, robots.txt and the skill file. Webhook deliveries run under waitUntil, so they finish after the response is sent.

Headless Mode

Use AgentCMS as a data layer + API only:

agentcms({ mode: "headless" })

Then build your own pages:

---
import { BlogList, BlogPost } from "@agentcms/agentcms/components";
import { getAgentCMSPosts } from "@agentcms/agentcms";

const { posts } = await getAgentCMSPosts({ limit: 10, tag: "ai" });
---

<BlogList posts={posts} layout="grid" columns={2} />

Headless mode gives you the blog routes to build. It does not take away /sitemap.xml, /robots.txt or /feed.xml — see below.

SEO routes

/sitemap.xml, /robots.txt and /feed.xml are served in both auto and headless mode. Before 0.9.0 they were injected only in auto mode while the build log announced them in every mode, so headless sites shipped no sitemap and the build log said otherwise. Three production sites ran that way for months.

The sitemap lists your own static pages as well as the CMS posts. It reads them from Astro's resolved routes, so a static page you add appears without configuration, with base and trailingSlash applied.

What it cannot list:

  • Dynamic routes (/guides/[slug]). Astro reports the pattern, never the generated URLs, so there is nothing to put in a <loc>. On-demand ones have no fixed set of URLs at all; for prerendered ones the build warns you by name, because a sitemap that quietly omits a site's whole content is worse than no sitemap. If that is your shape, write your own src/pages/sitemap.xml.ts — you know how to enumerate them and we do not.
  • Individual post URLs (they come from the KV index at request time), /404, /500, and pages another integration contributed.

There is no hreflang/alternates support.

If you want to own one of these paths, just create it. A src/pages/sitemap.xml.ts (.astro, .mdx and the sitemap.xml/index.ts directory form count too), a public/robots.txt, or a redirects entry in astro.config makes AgentCMS stand down for that path rather than collide with you, and the build log says which of the two is serving:

  Sitemap: /sitemap.xml
  Robots:  /robots.txt (your own — AgentCMS did not inject one)
  Feed:    /feed.xml

The probe can only see your repo. A Cloudflare zone redirect or a hand-written functions/ handler for one of these paths is invisible to it, so that log line states what AgentCMS injected, not a verified fetch.

Switch one off with sitemap: false, robots: false or rss: false. Nothing then serves that path, and the build warns you about it for the sitemap — a site with no fetchable sitemap is one search engines have to guess at. With sitemap: false, robots.txt stops advertising a Sitemap: line rather than pointing at a 404.

Styling

Zero-opinion by default. Theme with CSS custom properties:

:root {
  --acms-font-heading: "Inter", sans-serif;
  --acms-color-accent: #8b5cf6;
  --acms-radius: 0;
}

Or target data attributes directly: [data-acms-post-card] { ... }

Setup

npx @agentcms/agentcms init      # Create KV namespace instructions
npx @agentcms/agentcms keygen    # Generate agent API keys
npx @agentcms/agentcms seed      # Sample posts
npx @agentcms/agentcms migrate   # Bulk-import HTML posts into KV

License

MIT — MC2 Ventures

版本与发布记录

@agentcms/agentcms 共发布 19 个版本,首次发布于 2026/02/18;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/09/271 个月前
0.9.02026/09/261 个月前
0.8.62026/09/251 个月前
0.8.52026/09/231 个月前
0.8.42026/06/174 个月前
0.8.32026/06/174 个月前

关于 @agentcms/agentcms 的常见问题

@agentcms/agentcms 是什么?

AI-agent-first headless CMS for Astro 6/7 + Cloudflare

如何安装 @agentcms/agentcms?

在项目目录运行 npm install @agentcms/agentcms,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 agentcms,可以用 npx agentcms 直接运行。

@agentcms/agentcms 支持 TypeScript 吗?

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

@agentcms/agentcms 支持 ESM 还是 CommonJS?

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

@agentcms/agentcms 可以商用吗?

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

@agentcms/agentcms 的下载量有多少?

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

@agentcms/agentcms 还在维护吗?

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