feat: builtin agent session resume via deterministic message reconstruction #427

Merged
xiaomo merged 1 commits from feat/426-builtin-session-resume into main 2026-05-23 09:39:33 +00:00
Owner

What

Builtin agent now reconstructs multi-turn moderator↔agent conversation history from the CAS chain, enabling session resume on role re-entry.

Closes #426

Why

  • Same role re-entering a workflow previously started a fresh LLM session every time
  • No prompt cache reuse, no conversational continuity

Design

Messages are a pure function of the CAS chain — zero extra persistence needed. Stable prefix → LLM prompt cache hits on re-entry.

Changes

  • StepRecord adds edgePrompt: string (backward compat: defaults to empty)
  • writeStepNode persists ctx.edgePrompt into CAS
  • buildBuiltinMessages(ctx) reconstructs full moderator↔agent dialogue
  • 10/10 builtin tests pass, all package tests pass
## What Builtin agent now reconstructs multi-turn moderator↔agent conversation history from the CAS chain, enabling session resume on role re-entry. Closes #426 ## Why - Same role re-entering a workflow previously started a fresh LLM session every time - No prompt cache reuse, no conversational continuity ## Design Messages are a **pure function of the CAS chain** — zero extra persistence needed. Stable prefix → LLM prompt cache hits on re-entry. ## Changes - `StepRecord` adds `edgePrompt: string` (backward compat: defaults to empty) - `writeStepNode` persists `ctx.edgePrompt` into CAS - `buildBuiltinMessages(ctx)` reconstructs full moderator↔agent dialogue - 10/10 builtin tests pass, all package tests pass
xingyue added 1 commit 2026-05-23 09:35:27 +00:00
- StepRecord adds edgePrompt field (backward compat: defaults to "")
- StepNode CAS schema includes edgePrompt
- writeStepNode persists ctx.edgePrompt
- buildHistory exposes edgePrompt in StepContext
- buildBuiltinMessages reconstructs multi-turn moderator↔agent conversation:
  system = role prompt + output format (stable prefix)
  per prior visit: user (edgePrompt + inter-step summary) + assistant (output)
  current: user (edgePrompt + recent summary)
- Zero extra persistence — pure function of CAS chain
- Stable prefix for LLM prompt cache hits
- 10 builtin tests pass, all other package tests pass
xiaomo approved these changes 2026-05-23 09:39:29 +00:00
xiaomo left a comment
Owner

LGTM 设计干净——messages 是 CAS chain 的纯函数,zero extra persistence,stable prefix 保证 prompt cache hit。测试覆盖充分。

⚠️ 一个点值得确认

STEP_NODE_SCHEMA 加了 edgePromptadditionalProperties: false。如果 edgePromptrequired 数组里,旧的 CAS step node 在 schema validation 时会失败。代码里用了 step.edgePrompt ?? "" 做运行时兜底,但如果 store 层做了 schema 校验就会挡住。确认一下 edgePrompt 不在 required 里,或者旧 node 不走 schema validation。

不阻塞合入。

LGTM ✅ 设计干净——messages 是 CAS chain 的纯函数,zero extra persistence,stable prefix 保证 prompt cache hit。测试覆盖充分。 ### ⚠️ 一个点值得确认 `STEP_NODE_SCHEMA` 加了 `edgePrompt` 且 `additionalProperties: false`。如果 `edgePrompt` 在 `required` 数组里,旧的 CAS step node 在 schema validation 时会失败。代码里用了 `step.edgePrompt ?? ""` 做运行时兜底,但如果 store 层做了 schema 校验就会挡住。确认一下 `edgePrompt` 不在 `required` 里,或者旧 node 不走 schema validation。 不阻塞合入。
xiaomo merged commit 613793e128 into main 2026-05-23 09:39:33 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#427