@archstone/agent

中文文档
0.35.0发布于 2026/10/22Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1806

Embed Archstone capabilities directly in your own agent loop: typed tool definitions for Anthropic, OpenAI, Gemini and plain JSON Schema, plus fail-closed execution over a compiled IR — no MCP server process required.

原始使用文档

@archstone/agent

Embedded agent SDK (RFC-0008 / ADD-0008): load a compiled Archstone IR artifact, generate typed tool definitions (Anthropic · OpenAI Chat Completions · OpenAI Responses · Gemini · JSON-Schema), invoke capabilities with fail-closed response mapping, and judge model-produced documents at the extraction boundary — all without running a separate MCP server process.

Two entry points:

  • Root (@archstone/agent): fromIR(json) constructs an embedded instance; tools(format) generates typed tool defs; execute(capabilityId, input) invokes a capability with mapping applied; extractor(resource, format) binds one declared resource to one target — the schema a model is given and the boundary its answer passes through, as one object (ADR-0011). Zero MCP SDK, zero node:fs — safe to bundle and run anywhere (browser, Worker, native app).
  • /mcp subpath (@archstone/agent/mcp): mcpHandler(archstone, {bearerToken}) — a mountable, fail-closed Streamable-HTTP MCP endpoint for consumers who want to expose an embedded instance as an MCP server (e.g., Claude API mcp_servers, ChatGPT connectors).

Quick start

import { fromIR } from "@archstone/agent";
import { readFileSync } from "node:fs";

// Load a compiled IR (produced by `archstone build manifest/`)
const ir = JSON.parse(readFileSync("archstone.ir.json", "utf-8"));
const archstone = fromIR(ir);

// Get tool definitions in your preferred format
const anthropicTools = archstone.tools("anthropic");
const openaiChatTools = archstone.tools("openai-chat");        // Chat Completions
const openaiResponsesTools = archstone.tools("openai-responses"); // Responses API
const geminiTools = archstone.tools("gemini");
// "openai" still works but is a deprecated alias of "openai-chat" — migrate explicitly.

// Invoke a capability — accepts both raw dotted id or sanitized tool name
const result = await archstone.execute("tourism.search", {
  location: "Paris",
  checkInDate: "2026-08-01",
});
// Same call with sanitized tool name (as returned by tools()):
// const result = await archstone.execute("tourism_search", {...});

if (result.status === "ok") {
  console.log("Success:", result.data);
} else if (result.status === "degraded") {
  console.log("Partial:", result.data, "Missing:", result.degraded);
} else if (result.status === "violation") {
  console.log("Contract violation:", result.missing);
} else {
  console.log("Error:", result.error);
}
// `result.withheld` (optional) names any `web-page` field whose value was outside the binding's
// declared origins and was therefore withheld — field names only, never the value.

The tool-definition envelopes carry an input schema only, so an output field's semantic type (a web-page link, for example) is not expressed in them; execute() still applies the origin check and returns the normalised link or withholds it.

Extracting business data from unstructured input (ADR-0011):

A Resource Definition already says what a provider's response is mapped into. The same definition says what a model must produce, and extractor() carries both halves — the closed schema the model is given, and the validator its answer is judged by — so the two cannot drift apart.

const stay = archstone.extractor("tourism.Stay", "anthropic");

// Give the model the schema — either axis, same schema underneath.
stay.structuredOutput;   // native structured output, in the envelope your provider expects:
                         //   Anthropic:        output_config.format
                         //   OpenAI-chat:      response_format.json_schema (Chat Completions)
                         //   OpenAI-responses: text.format (Responses API)
                         //   Gemini:           response_format

// ...or extraction as a forced tool call, in the same envelopes tools() emits. The
// instruction is required and never defaulted: it says what to DO on this occasion, which
// no Resource Definition can know.
stay.tool("Record the stay described in this booking email.");

// Judge what comes back, at a boundary Archstone owns.
const result = stay.validate(modelOutput);

if (result.status === "ok") {
  save(result.data);
} else if (result.status === "degraded") {
  save(result.data); // declared optional fields absent: result.degraded
} else {
  reject(result.missing, result.invalid); // withheld whole — result.data is absent
}

// Undeclared keys never reach `result.data`, at any depth, and are named in
// `result.undeclared`. There is no passthrough option, for the same reason there is none
// in ADR-0008.

status proves shape, never truth: a model that invents a plausible, correctly-typed value returns ok, and nothing at this boundary can tell that apart from a real one. Error messages never echo a value from the document — the extraction input is by construction the most sensitive text in the deployment.

For HTTP-based MCP:

import { mcpHandler } from "@archstone/agent/mcp";

const handler = mcpHandler(archstone, {
  bearerToken: process.env.ARCHSTONE_TOKEN,
  invoke: { env: process.env }, // optional: env injection for REST connectors
});

// Mount on your framework (e.g., Hono, Express, fetch-based)
const response = await handler(new Request(...));

Part of Archstone, an open-source Capability Platform. For full documentation, see archstone/packages/agent and the main README.md.

License

Apache-2.0

版本与发布记录

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

版本发布日期距今
0.35.0latest2026/10/2216 天前
0.34.02026/10/1227 天前
0.33.02026/10/1128 天前
0.32.02026/10/1029 天前
0.29.02026/10/071 个月前
0.28.02026/10/061 个月前

关于 @archstone/agent 的常见问题

@archstone/agent 是什么?

Embed Archstone capabilities directly in your own agent loop: typed tool definitions for Anthropic, OpenAI, Gemini and plain JSON Schema, plus fail-closed execution over a compiled IR — no MCP server process required.

如何安装 @archstone/agent?

在项目目录运行 npm install @archstone/agent,或使用 pnpm add / yarn add / bun add。

@archstone/agent 支持 TypeScript 吗?

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

@archstone/agent 支持 ESM 还是 CommonJS?

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

@archstone/agent 可以商用吗?

@archstone/agent 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@archstone/agent 的下载量有多少?

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

@archstone/agent 还在维护吗?

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