Feature request: Add structured memory primitives for better context engineering #791
+1,556
−1
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.
feat(memory): Add Session, WorkingContext, and Processor Pipeline primitives
Summary
This PR introduces structured memory primitives for building context-aware agents, based on the tiered memory architecture principles from Google's ADK whitepaper.
Why?
Currently, agent developers must manually manage conversation history, handle context window limits, and implement their own compaction strategies. This leads to:
These primitives provide a model-agnostic foundation that separates the ground truth (Session) from the computed view (WorkingContext), enabling clean abstractions for context management and compaction.
What's Added
1. Session - The Ground Truth
A durable, structured log of agent interactions. Sessions are model-agnostic and serve as the source of truth.
2. WorkingContext - The Computed View
An ephemeral, computed view sent to the LLM. Rebuilt for each invocation.
3. Processor Pipeline - Modular Context Building
A pipeline of processors that transform Session state into WorkingContext, inspired by Google ADK's processor pattern.
Built-in Request Processors:
Built-in Response Processors:
Bonus: Compaction Without Model Coupling
The primitives enable context compaction without worrying about underlying model structure:
Why this matters:
Event Types
Strongly-typed events for all agent interactions:
Current Limitations
Files Added