Show HN: Kastor – 用于 AI 智能体的 Terraform 风格规范
Show HN: Kastor – Terraform-style specs for AI agents

原始链接: https://github.com/weirdGuy/kastor

Kastor 是一个厂商中立的“AI 智能体版 Terraform”,它提供了一种声明式的方法来定义、版本化和管理智能体工作流。Kastor 不会将智能体硬编码在特定的框架中,而是使用基于 HCL 的类型化规范(.agent、.tool、.prompt 文件)来创建单一事实来源。 该工具链具备两种运行模式: 1. **构建(Build):** 将声明式规范编译为 LangGraph 等框架的可运行项目。 2. **调和(Reconcile/Plan/Apply):** 将智能体作为长生命周期资源进行管理,提供跨托管平台的偏差检测和状态管理(计划于 v0 版本实现)。 Kastor 并非一种新的运行时,而是一个弥合智能体设计与部署之间差距的管理层。通过将基础设施配置与智能体逻辑分离,它使开发者能够维护可复现、可审查的智能体定义。 目前,Kastor 支持针对 LangGraph 的项目验证和编译。这是一个处于早期阶段的概念验证项目,未来的路线图包括直接的平台部署(AWS/Azure)以及自动化的偏差检测。开发者可以通过 Homebrew、Go 或手动安装二进制文件来开始使用。详细的文档和架构决策记录在项目的 `SPEC.md` 中。

Kastor 是一个全新的开源项目,它引入了一种受 Terraform 启发的声明式方法来管理 AI 智能体。创作者“weirdguy”开发了这一基于 Go 语言的命令行工具(CLI),旨在解决智能体配置碎片化的问题,因为目前的配置往往散落在不同的提示词文件、框架代码、工具定义和环境变量中。 通过使用 HCL(HashiCorp 配置语言),Kastor 提供了一个集中的“单一事实来源”,使得智能体的定义能够实现版本控制、可复现,且更易于审查。该项目目前已具备 HCL 解析器、依赖检查以及 LangGraph 代码生成功能。 该项目的长期愿景是将 AI 智能体视为“基础设施即代码”(IaC)。开发者并不打算构建一个新的智能体运行时,而是希望提供一种“计划与应用”(plan and apply)的工作流,将配置编译为框架代码,并将其与托管的智能体平台协调,以管理状态并检测配置偏差。创作者目前正在寻求关于语言设计以及将 IaC 原则应用于智能体开发的反馈。
相关文章

原文

Kastor is "Terraform for AI agents." Agents today are defined imperatively inside frameworks (LangGraph, CrewAI) or clicked together in platform UIs (OpenAI Assistants, Bedrock Agents) — there is no vendor-neutral, versionable, reviewable source of truth. Kastor provides one: a typed, declarative spec (.agent, .tool, .prompt files in HCL) and a Go toolchain with two paths — kastor build generates runnable projects for target frameworks, and kastor plan / kastor apply reconcile agents as long-lived resources on hosted platforms, with state, diffs, and drift detection.

The full design lives in SPEC.md.

Kastor is an early proof of concept.

Working today:

  • parse .agent, .tool, .prompt, and kastor.hcl
  • validate references and prompt variables
  • build runnable LangGraph projects
  • examples: weather agent, content scheduler agent

Planned for v0:

  • kastor plan/apply
  • local state file and drift detection
  • Deploy to aws/azure platforms.

This is not another agent runtime/framework.

Homebrew:

brew tap weirdGuy/tap && brew install kastor

Install script (verifies the release checksum, installs to /usr/local/bin or ~/.local/bin, never sudo):

curl -fsSL https://raw.githubusercontent.com/weirdGuy/kastor/main/scripts/install.sh | sh

With Go 1.26+:

go install github.com/weirdGuy/kastor/cmd/kastor@latest

Or download an archive for your platform from the releases page, verify it against checksums.txt, and put the kastor binary on your PATH.

Quickstart: build the weather example

Prerequisites: Go 1.26+, Python 3.11+, an OpenAI API key, and a Tavily API key (the example's search tool runs against Tavily's hosted MCP server).

Compile the spec to a LangGraph project:

go build ./cmd/kastor
./kastor validate examples/weather/
./kastor build examples/weather/

kastor build writes the generated project to examples/weather/gen/langgraph (the target's declared output). Generated output is not committed: it is reproducible from the spec, and codegen determinism is enforced by tests.

Set up the generated project:

cd examples/weather/gen/langgraph
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

The example's web_search tool is pinned to an MCP server and tool by its spec URI, mcp://search-server/tavily_search. How to reach that server is deployment configuration, not spec: create mcp_servers.json in the working directory (or point the KASTOR_MCP_CONFIG env var at a file elsewhere). For Tavily's hosted server:

{
  "search-server": {
    "transport": "streamable_http",
    "url": "https://mcp.tavily.com/mcp/?tavilyApiKey=tvly-YOUR-KEY"
  }
}

The URL embeds your API key, which is why mcp_servers.json is gitignored — treat it as a secret, never commit it. Also note the spec URI's last path segment (tavily_search) must name a tool the server actually advertises, or calls fail with "does not expose tool".

Export the model credential (the example's model "fast" block uses provider openai):

export OPENAI_API_KEY=sk-...

Run the agent:

python3 main.py weather --inputs '{"location": "Lisbon", "date": "tomorrow"}'

It prints the agent's declared output contract as JSON:

The generated README.md inside gen/langgraph owns the run-the-project side in full: every agent's inputs and outputs, tool bindings, and MCP configuration.

One v0 caveat (SPEC.md §3.2/§4): agent.weather's optional forecast_context input references agent.forecast's output. That reference is validated at compile time and orders the dependency graph, but generated code does not run the upstream agent for you — if you want the context, run forecast yourself and pass its summary via --inputs.

go build ./...   # build everything
go test ./...    # run all tests

SPEC.md is the source of truth for design decisions; CLAUDE.md documents the day-to-day conventions.

联系我们 contact @ memedata.com