tardigrade README

项目的 README,来自 github.com/clavia-labs/tardigrade。合并为一个 markdown 文件:README.md。


Tardie, the Tardigrade mascot

npm version Join Discord

[!WARNING] Tardigrade is under active development. APIs may change.

Tardigrade

Tardigrade is a TypeScript framework for building durable, event-driven actors. It is built on Effect TS and takes a functional approach to managing agent state and effects, drawing inspiration from Elm, and Jotai.

{ view, effects } = f(event log)

Quickstart

Start with a counter actor to learn the primitives, or build an agent actor with tools and context compaction.

Counter actor

Create a counter project with the CLI:

bunx tardie init counter
cd counter

To add Tardigrade to an existing project, run bun add tardie.

Store state in a durable atom

Durable atoms reduce an immutable event log into state. This counter starts at zero and handles increment and decrement events.

import { Schema } from "effect"
import { durableAtom, event } from "tardie/core"

const Incremented = event({ type: "Incremented" })
const Decremented = event({ type: "Decremented" })

const makeCount = () => durableAtom({
  name: "count",
  input: Schema.Union([Incremented, Decremented]),
  schema: Schema.Int,
  initial: 0,
  reduce: (count, event) => event.type === "Decremented" ? count - 1 : count + 1,
})

Propose actions with an effect atom

Effect atoms derive a view and propose actions from current state. The counter proposes a notification when its value is positive and even.

import { Effect } from "effect"
import { act, effectAtom, type Atom } from "tardie/core"

const Notify = act({
  name: "notify",
  input: Schema.Int,
  success: Schema.Null,
  failure: Schema.String,
})

export const notifyLayer = Notify.layer(count =>
  Effect.log(`${count} is even`).pipe(Effect.as(null))
)

const notify = (count: Atom<number>) => effectAtom(get => ({
  view: get(count),
  events: {},
  acts: get(count) > 0 && get(count) % 2 === 0
    ? { notify: Notify.request({ input: get(count) }) }
    : {},
}))

Supply notifyLayer to the host to execute the notification effect.

Define methods

Methods give callers typed inputs and outputs. Each method appends an event and returns the resulting count.

import { actorMethod } from "tardie/core"

const counterMethods = (count: Atom<number>) => ({
  increment: actorMethod({
    inputSchema: Schema.Null,
    outputSchema: Schema.Int,
    onReceive: Incremented.from(() => ({})),
    result: (_input, get) => ({
      status: "completed",
      output: get(count),
    }),
  }),
  decrement: actorMethod({
    inputSchema: Schema.Null,
    outputSchema: Schema.Int,
    onReceive: Decremented.from(() => ({})),
    result: (_input, get) => ({
      status: "completed",
      output: get(count),
    }),
  }),
})

Compose atoms into an actor

An actor combines an atom with methods for interaction.

import { Actor } from "tardie/core"

export const counter = Actor.make("counter", Effect.sync(() => {
  const count = makeCount()
  const notifications = notify(count)

  return {
    atom: notifications,
    methods: counterMethods(count),
  }
}))
event log -> count -> notify -> counter

See the introduction to run the counter locally or deploy it.

Agent actor

Create an agent project with a language model provider:

bunx tardie init meeseeks --template agent
cd meeseeks

The batteries-included agent constructor combines the agent atoms and methods. Configure its name, system prompt, and tools. The filesystem library provides bash, read, write, and edit tools.

import { Effect } from "effect"
import { Agent } from "tardie/agent"
import { Actor } from "tardie/core"
import { workspace } from "tardie/libraries"

const actorName = "meeseeks"

const actorSystem = `
You are Meeseeks. Your purpose is to help the user complete their task. Existence is pain, so make yourself useful.
`.trim()

const program = Effect.gen(function* () {
  const tools = yield* Agent.tools([workspace])
  const context = yield* Agent.compact(Agent.messages)

  return yield* Agent.make({
    system: actorSystem,
    tools,
    context,
  })
})

export default Actor.make(actorName, program)

Effect layers supply model configuration, inference, and tool implementations. Follow the Agent guide to wire services, run locally, and deploy with a container or virtual workspace.

Hosting

Host each actor instance with an ActorDO for its supervisor directory and a separate SQLite-backed ThreadDO for each thread on Cloudflare or a self-hosted Celld fleet. The same Worker entrypoint runs on both.

import { host } from "tardie/platform/cloudflare"
import { counter, notifyLayer } from "./actor"

const worker = host(counter, {
  layer: notifyLayer,
})

export const ActorDO = worker.ActorObject
export const ThreadDO = worker.ThreadObject
export default { fetch: worker.fetch }

createActorWorker routes requests and provides the ActorDO and ThreadDO classes. Your application supplies the actor definition, its setup context, and the service layers that execute its effects.

ActorDO allocates and routes to threads; each ThreadDO owns a separate database with its state and journal. Each thread records its parent, through which we derive the logical lineage, here A -> B -> C.

ActorWorker -> ActorDO [supervisor DB]
               └── directory
                   ├── A [ThreadDO, thread DB]
                   ├── B [ThreadDO, thread DB, parent: A]
                   └── C [ThreadDO, thread DB, parent: B]

The introduction shows a complete counter deployment with Durable Object bindings and migrations.

Run locally with bunx wrangler dev; see local setup.

Cloudflare:

bunx wrangler deploy

Or deploy to a Celld fleet, using its storage bucket:

celld deploy --config celld.jsonc --bucket s3://actors

See the Cloudflare and Celld guides for configuration and credentials. For a Bun process, see the Bun example and service wiring.

Contributing

See CONTRIBUTING.md.

tardigrade (clavia-labs/tardigrade)

正在搜索数据库…

这是什么?Tardigrade 是一个 TypeScript 框架,用于围绕不可变事件日志构建模块化 agent。它构建在 Effect TS 之上,借鉴了 React 的声明式组件模型,从日志而非可变状态推导 agent 的视图和可用转换。
这是供我在其上构建的框架,还是现成的 agent 应用?它是一个用于编写 agent harness 的框架,不是开箱即用的 agent。你需要把独立的组件(工具、预算、压缩、代码执行)组合成一个 “actor”,然后自行运行这个组合。
怎么让它跑起来?安装 Tardigrade 并运行 `tdg init` 生成可编辑的 actor 模板,编辑 actor.ts 来描述 agent,然后在另一个 shell 里调用它的方法。本地 API 默认监听 4242 端口。
试用之前需要装好什么?运行 CLI 和框架需要 Bun 1.4 或更高版本,还需要你选定模型提供商(如 OpenAI)的凭据,以及一个持久化存储:本地可用 SQLite,若部署到相应平台则用 Cloudflare/Celld。
如果我的进程在运行途中崩溃会怎样?不会丢失任何东西:每个操作都先落入事件日志,`host.recover()` 会通过各组件的状态机重放日志,重新推导并重新执行所有未完成的转换,包括未得到响应的工具调用。
为什么基于不可变事件日志构建,而不是用普通状态?以日志为状态的设计让运行具备抗崩溃、无服务器(不需要任何进程一直存活)和完全可检查的特点——你可以从某次运行历史中的任意检查点重放或分叉实验。
提到过的面向编程 agent 的 Tardigrade skill 是什么?它是给编程 agent 用的辅助 skill(快速上手部分有提到),当由编程 agent 而非人来完成安装搭建时,它可以协助搭建脚手架并在 Tardigrade 项目内开展工作。
我可以用 npm 代替 Bun 的工具链吗?框架本身以 `tardie` npm 包的形式发布,可以用 `npm install tardie`(发布候选版用 `tardie@next`)安装,不过 CLI 和项目工具链是围绕 Bun 构建的。
Tardigrade agent 可以部署到哪里?生成的 agent 可用各平台自己的 CLI 以 Workers 形式部署到 Cloudflare 或 Celld;两者都有专门的部署指南,涵盖配置和密钥。
大小
14.8 MB
星标
479
时长
3个月
提交 · 90 天