Skip to content

开源 · Pre-GA · Apache 2.0

构建、托管并编排
可调用工具的
AI Agent

Agentrail 提供可组合的运行时、面向托管场景的服务层、多 Agent 编排能力,以及清晰的扩展模型,同时保留自托管与自行组合的空间。

agent.ts
import { defineAgent } from "@agentrail/core";
import { defineProfile } from "@agentrail/app";

export const researchAgent = defineAgent({
  id: "researcher",
  model: {
    provider: "anthropic",
    modelId: "claude-sonnet-4-5",
    apiKey: process.env.ANTHROPIC_API_KEY,
  },
  system: "You are a research assistant.",
});

// stream a response
const result = await researchAgent.stream(
  "What are the latest advances in agentic AI?",
);

处在合适的抽象层级。

很多团队会落在两个极端之间:一边是难以扩展的脚本集合,另一边是带来强绑定的平台。Agentrail 位于两者之间。

结构过少

临时脚本

  • 缺少 Session 管理
  • 工具契约隐含在代码中
  • 编排方式每次都要重写
  • 测试成本高
  • 后续扩展常常需要返工

绑定过强

托管平台

  • 内部实现不透明
  • 计费方式难以预估
  • 扩展能力受限
  • 数据受制于供应方
  • 以 GUI 为主,而非以代码为主

覆盖交付 Agent 所需的核心部分。

文档与包结构按职责划分。每个包职责明确,也可以单独使用。

@agentrail/core

Agent 运行时

用于定义 Agent 与类型化工具契约。LLM 循环、工具调度、LLM Provider 抽象、Prompt SDK 与用量统计都位于这一层。

@agentrail/capabilities

能力包

提供沙箱文件系统与浏览器工具、知识库检索、技能注册以及多 Agent 编排,可通过 defineProfile({ capabilities: [...] }) 组合到 Profile 中。

@agentrail/app

Host 层

createAgentApp 一次挂载聊天与流式接口,defineProfile 负责连接模型、Prompt 与能力。Session 管理、Plugin、Slash Command 与配置加载也位于这一层。

@agentrail/capabilities · orchestration

多 Agent 编排

用于创建子 Agent、分发结构化任务、等待条件完成,并在失败后恢复。状态可通过基于 JSONL 的邮箱机制跨重启保留。

@agentrail/app · SessionManager

Session 管理

基于文件系统的 Session 存储,使用追加式 JSONL 历史记录,并支持自动上下文压缩与会话分支。

@agentrail/capabilities · sandbox

沙箱执行

基于 Docker 的隔离执行环境,用于浏览器自动化、Shell 命令与文件读写,并按 Session 维度隔离。

几分钟内完成初始化。

npx @agentrail/cli@latest create
阅读快速开始 →

按层组织。

优先使用推荐的 SDK 入口;需要更细控制时,再下探到底层原语。

4业务应用
Profile路由UI业务逻辑
↓ 依赖于
3@agentrail/app
createAgentAppdefineProfileSessionManagerPluginSlash CommandConfig
↓ 依赖于
2@agentrail/capabilities
包含 →
FilesystemBrowserKnowledgeSkillsOrchestrationToolsSandboxMemory Context
↓ 依赖于
1@agentrail/core基础层
Agent LoopTool ContractLLM Provider APIPrompt SDKSession Types