正在打开每日关注
正在打开每日关注
作者用香蕉蛋糕类比讲透 Effect TS 服务与分层,并推荐事件日志驱动的模块化 Agent 框架 Tardigrade 作为实例参考。
If you want a decent reference for this pattern with Effect TS, point your agents over here: https://t.co/hupCL4ogkg https://t.co/N2eYAXD2Am
If the Effect TS concept of services and layers are confusing, I have a little analogy for you. Imagine you want to make banana cake. An Effect program is the recipe to make one. Services describe the capabilities you need (something to hold, something that can whisk, something that can heat things etc.) Layers describe how to provide these capabilities in specific environments (a box, a whisk, an oven in a kitchen OR something completely make do like a bowl, your fingers, and the sun when outside). Writing your code like this forces you to discover the pure logic of your system. Everything else is layer above this so it can be interpreted by different runtimes.
是什么:Tardigrade 是 clavia-labs 开源的 TypeScript 框架(348 stars,2026-08 创建,持续活跃),用于围绕不可变事件日志构建模块化 Agent,构建在 Effect TS 之上,函数式思路受 Elm 与 Jotai 启发。原推作者 june 转发它,是将其作为 Effect TS services/layers 模式的真实代码参考。
核心设计:核心等式 { view, effects } = f(event log)——一切视图与副作用都由事件日志归约而来。实现上分三层抽象:普通 atom 存储状态并支持派生;durable atom 把事件日志归约为持久状态(如对话历史);effect atom 派生视图并提出动作(如按阈值触发 compact 摘要压缩)。托管层采用 Actor 模型:ActorDO 充当监督目录,每个 ThreadDO 独享 SQLite 数据库,通过 parent 字段推导 A→B→C 的逻辑谱系。配图正展示了仓库对服务与分层的落地:core/services 定义运行时能力(event-log、journal、alarm、supervisor 等),platform 层(bun / cloudflare / shared)为不同环境提供具体实现,同一 Worker 入口可跑在 Cloudflare 或自托管 Celld。
关键洞察:引用推文用香蕉蛋糕类比点明要义——Services 是所需能力(能搅拌、能加热),Layers 是具体环境下的供给(厨房烤箱或户外阳光)。这种分离强迫开发者先发现系统的纯逻辑,再让不同运行时去解释,配图的目录结构就是该理念的工程化印证。项目还为编码 Agent 提供 SKILL.md。
边界与风险:项目处于活跃开发期,README 明确警告 API 可能变动;star 数尚少、生态未成熟;需要同时理解 Effect TS 与事件溯源,学习曲线较陡。