Skip to content

feat(workflow): add ContextAssembler and IncrementalSaver optional interfaces#2

Merged
lIang70 merged 2 commits into
mainfrom
feat/optional-session-interfaces
Apr 14, 2026
Merged

feat(workflow): add ContextAssembler and IncrementalSaver optional interfaces#2
lIang70 merged 2 commits into
mainfrom
feat/optional-session-interfaces

Conversation

@lIang70

@lIang70 lIang70 commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add optional ContextAssembler interface: when a MemorySession implements it, Runtime calls Assemble(ctx, req) instead of Load(ctx) during prepareBoard, allowing custom context assembly (RAG, summarization, sliding window, etc.). The returned messages do NOT include req.Message; the runtime appends it uniformly.
  • Add optional IncrementalSaver interface: when implemented, Runtime calls Append(ctx, newMsgs) with only the newly produced messages instead of Save(ctx, allMsgs), enabling efficient incremental persistence for database-backed stores.
  • Both interfaces are detected via runtime type assertion. The MemorySession interface itself remains unchanged, and all existing implementations require no modifications.

Changed files

File Change
sdk/workflow/memory.go Add ContextAssembler and IncrementalSaver interface definitions
sdk/workflow/run.go prepareBoard prefers Assemble; finishRun prefers Append
sdk/workflow/run_integration_test.go Add 3 tests covering the new code paths

Test plan

  • TestRuntime_ContextAssembler — verify Assemble is called, req is passed in, req.Message is appended by Runtime
  • TestRuntime_IncrementalSaver — verify Append receives only the new messages
  • TestRuntime_ContextAssembler_And_IncrementalSaver — verify both interfaces work in combination
  • All existing tests pass (no regressions)

lIang70 added 2 commits April 14, 2026 17:57
…terfaces

Introduce two optional interfaces for MemorySession without changing the
existing contract:

- ContextAssembler: when implemented, Runtime calls Assemble(ctx, req)
  instead of Load(ctx), allowing custom context assembly (RAG, summarization,
  sliding window). Returned messages do NOT include req.Message; the runtime
  appends it uniformly.

- IncrementalSaver: when implemented, Runtime calls Append(ctx, newMsgs)
  instead of Save(ctx, allMsgs), enabling efficient incremental persistence.

Both interfaces are detected via type assertion at runtime, keeping
MemorySession simple and all existing implementations unaffected.

Made-with: Cursor
@lIang70
lIang70 merged commit 7be2441 into main Apr 14, 2026
8 checks passed
@lIang70
lIang70 deleted the feat/optional-session-interfaces branch April 14, 2026 10:02
lIang70 added a commit that referenced this pull request May 21, 2026
Harden lease-recycle recovery under scope lock, transient retry with
RetryAt/Attempt persistence, and require Scope/RuntimeID for drain and
stats so workers cannot claim or observe cross-tenant queue state.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant