feat(contexts): add advisory memory context with logged recall effect#32
Open
sorcerai wants to merge 1 commit into
Open
feat(contexts): add advisory memory context with logged recall effect#32sorcerai wants to merge 1 commit into
sorcerai wants to merge 1 commit into
Conversation
Contributor
|
Thank you for your contribution! I'll review this and get back later today. |
Contributor
|
I've done a preliminary review. This is clever and useful, and I'm interested in taking this on. We have some changes currently cooking that partially intersect with this, both on the arch and capability side. I'll need to do some careful thinking about how to make these work well together. I'll do my best to have a more cohesive path forward by tomorrow! Thanks so much for the contribution – and for your patience. The concrete is still setting on this framework + project + infrastructure in many places, and so things will take longer for a little while! |
MemoryContext surfaces cross-run advisory memory into a task's system prompt and records what it surfaced as a MemoryRecalled effect in the trace, so what influenced a run is auditable (never an invisible prompt mutation). Memory is advisory-only: apply_effect is a no-op, so it never enters the state(t)=fold(apply_effect, ...) derivation and never justifies a release. - MemoryBackend Protocol + InMemoryBackend (deterministic, zero-dep default); concrete backends for an external substrate live out-of-tree. - MemoryRecalled effect, registered via the shepherd.effects entry-point contributor; round-trips through the composed registry. - observations_from_effects: derive bugfix/decision observations from TaskFailed / settlement (select/discard) for out-of-band capture. Follows the KVStoreContext reference pattern; entry points registered under shepherd.contexts + shepherd.effects.
c4a7f81 to
ba24951
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an advisory memory context — a new reference context that surfaces cross-run memory into a task's system prompt and records what it surfaced as a logged effect in the trace.
Shepherd's concepts docs note that cross-run memory is absent today (
workspaces.md: "configuration, not history";runs.md: manual compare only). This fills that gap with a context that follows the existingKVStoreContextreference pattern.What's included
MemoryContext— recalls advisory hints into the prompt and emits aMemoryRecalledeffect. Advisory-only:apply_effectis a no-op, so memory never entersstate(t) = fold(apply_effect, ...)and never justifies a release.MemoryRecalledeffect — the audit record (query, backend, hint titles + digests). Registered via theshepherd.effectsentry-point contributor; round-trips through the composed registry.MemoryBackendProtocol +InMemoryBackend— pluggable backend SPI with a deterministic, zero-dependency default. Concrete backends for an external substrate live out-of-tree.observations_from_effects— derive bugfix/decision observations fromTaskFailed/ settlement (select/discard) for out-of-band capture.Design
MemoryRecalledrecords exactly what reached the prompt — the recall is in the trace, not a hidden prompt mutation.apply_effectreturnsself; memory shapes the prompt but never the effect-replay fold or a release.configure(). Recall happens eagerly increate();configure()only reads the already-recalled hints.contexts; noshepherd2/shepherd.kernel.abi.v0touch.Test coverage
27 tests (unit + end-to-end with the deterministic
MockProvider): recall surfaces hints into the provider binding'ssystem_prompt_additions,MemoryRecalledlands in the trace with correct provenance, the recall round-trips through the composed registry, advisory-only guarantees (no-opapply_effect, invisible body, only read/lifecycle effects on the binding), backend protocol conformance,max_hintstruncation, and the write-path extraction (TaskFailed → bugfix, settlement → decision/anti-pattern).ruffand strictmypyclean for the package; no regressions in thecontextssuite (275 passed).Known limitations
MemoryRecalledis emitted at extract time (after execution). A run that fails before extract emits onlyTaskFailed, not the recall record —ContextConfiguredstill records that a memory binding was active. Emitting the recall before execution would require a framework hook to publish effects at configure/prepare time.ProviderBinding.system_prompt_additions, the same channel every context uses. Any device/container execution mode that does not propagatesystem_prompt_additions(a framework-wide concern, not specific to memory) will omit the hints there; the in-process path is unaffected.Follows
CONTRIBUTING.md(Conventional Commits title;make baseline+ quickstart green on macOS).