feat: Merkle Call Stack — cross-thread DAG linking for workflowAsAgent #194

Closed
opened 2026-05-12 01:30:28 +00:00 by xiaoju · 1 comment
Owner

Summary

workflowAsAgent 场景下,父子 thread 之间建立双向 Merkle 链接,形成调用栈结构。

Problem

当前父子 workflow 之间没有 CAS 层面的链接:

  • 子 thread 不知道自己从哪来,无法追溯父 thread 的上下文
  • 父 thread 不知道子 thread 在哪,child thread hash 埋在文本里
  • 上下文只能序列化到 prompt 传递,丢失 Merkle DAG 可遍历性

Design

详见 RFC: docs/plans/2026-05-11-merkle-call-stack.md

新增字段

链接方向 字段 所在节点 指向
子→父 StartNodePayload.parentState 子 thread start node 父 thread 调用时的 head state hash
父→子 StateNodePayload.childThread 父 role state node 子 thread 最终 state hash

两者同时放进 refs[],GC 自然正确。

Implementation Phases

  • Phase 1: Protocol + CAS 层(cas-types, nodes.ts)
  • Phase 2: Engine 层(executeThread, workflowAsAgent)
  • Phase 3: Agent 可观测性(buildAgentPrompt, CLI thread show)
  • Phase 4: 测试验证

Open Questions

  1. 一个 role 能否 spawn 多个子 workflow?(childThread 单值 vs 数组)
  2. agent 自动遍历父上下文的深度限制?
  3. CLI thread show 要不要递归展示调用栈?
## Summary 在 `workflowAsAgent` 场景下,父子 thread 之间建立双向 Merkle 链接,形成调用栈结构。 ## Problem 当前父子 workflow 之间没有 CAS 层面的链接: - 子 thread 不知道自己从哪来,无法追溯父 thread 的上下文 - 父 thread 不知道子 thread 在哪,child thread hash 埋在文本里 - 上下文只能序列化到 prompt 传递,丢失 Merkle DAG 可遍历性 ## Design 详见 RFC: `docs/plans/2026-05-11-merkle-call-stack.md` ### 新增字段 | 链接方向 | 字段 | 所在节点 | 指向 | |---------|------|---------|------| | 子→父 | `StartNodePayload.parentState` | 子 thread start node | 父 thread 调用时的 head state hash | | 父→子 | `StateNodePayload.childThread` | 父 role state node | 子 thread 最终 state hash | 两者同时放进 `refs[]`,GC 自然正确。 ## Implementation Phases - [ ] Phase 1: Protocol + CAS 层(cas-types, nodes.ts) - [ ] Phase 2: Engine 层(executeThread, workflowAsAgent) - [ ] Phase 3: Agent 可观测性(buildAgentPrompt, CLI thread show) - [ ] Phase 4: 测试验证 ## Open Questions 1. 一个 role 能否 spawn 多个子 workflow?(`childThread` 单值 vs 数组) 2. agent 自动遍历父上下文的深度限制? 3. CLI `thread show` 要不要递归展示调用栈?
Author
Owner

Phase Testing Issues

  • Phase 1: Protocol + CAS 层 → #195
  • Phase 2: Engine 层 → #196
  • Phase 3: Agent 可观测性 → #197

按 RFC iteration 流程逐 phase 实现 + 验证。

## Phase Testing Issues - [ ] Phase 1: Protocol + CAS 层 → #195 - [ ] Phase 2: Engine 层 → #196 - [ ] Phase 3: Agent 可观测性 → #197 按 RFC iteration 流程逐 phase 实现 + 验证。
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#194