feat(adk): add pluggable memory middleware - #1230
Open
Ethanz11-creat wants to merge 1 commit into
Open
Conversation
Add a reusable ADK middleware that connects the agent lifecycle hooks to an application-provided MemoryStore, so long-running agents can retrieve and inject long-term memory before a run and optionally write facts or summaries back after a run. The middleware injects memory once per run (before the first model call) to avoid re-injecting on every tool-call loop, resolves a configurable memory namespace in BeforeAgent, and delegates persistence decisions to a WritePolicy invoked in AfterAgent. Memory backend implementations stay outside eino core; the middleware only depends on the MemoryStore interface (closes cloudwego#995).
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.
Closes #995
Adds a pluggable long-term memory middleware under
adk/middlewares/memorythat connects the ADK agent lifecycle hooks to an application-providedMemoryStore.Why
Long-running or general-purpose agents need to retrieve relevant memory before a run and persist facts/preferences/summaries afterward. Today each application wires its own injection and write logic against
Retriever/Indexer/Embedding. This middleware gives that a standard shape while keeping the storage backend outside Eino core.What it does
MemoryStoreinterface —Search/Save, withMemoryOption(currentlyWithNamespace) for per-operation scoping.Configwith four optional hooks, all defaulted:NamespaceResolver— namespace per run (default: shared).QueryBuilder— retrieval query from conversation state (default: most recent user message).MemoryFormatter— docs → messages to inject (default: one[memory]system message per doc).WritePolicy— what to persist after a terminal state (default: nothing).BeforeModelRewriteState(not re-injected on every tool-call loop), and written inAfterAgent.Scope notes
This first increment targets the default
*schema.Messageagent (adk.ChatModelAgentMiddleware). A genericTypedChatModelAgentMiddleware[M]variant and richer defaults (e.g. summarization-based write policy) can follow if maintainers want them. No vector database is introduced to core — theMemoryStoreimplementation stays in the application or eino-ext.Tests
go test ./adk/middlewares/memory/covers required-store validation, once-per-run injection, namespace-scoped writes viaWritePolicy, and no-op whenWritePolicydeclines.