Skip to content

feat(adk): add pluggable memory middleware - #1230

Open
Ethanz11-creat wants to merge 1 commit into
cloudwego:mainfrom
Ethanz11-creat:feat/adk-memory-middleware
Open

feat(adk): add pluggable memory middleware#1230
Ethanz11-creat wants to merge 1 commit into
cloudwego:mainfrom
Ethanz11-creat:feat/adk-memory-middleware

Conversation

@Ethanz11-creat

Copy link
Copy Markdown

Closes #995

Adds a pluggable long-term memory middleware under adk/middlewares/memory that connects the ADK agent lifecycle hooks to an application-provided MemoryStore.

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

  • MemoryStore interface — Search / Save, with MemoryOption (currently WithNamespace) for per-operation scoping.
  • Config with 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).
  • Memory is injected once per run in BeforeModelRewriteState (not re-injected on every tool-call loop), and written in AfterAgent.

Scope notes

This first increment targets the default *schema.Message agent (adk.ChatModelAgentMiddleware). A generic TypedChatModelAgentMiddleware[M] variant and richer defaults (e.g. summarization-based write policy) can follow if maintainers want them. No vector database is introduced to core — the MemoryStore implementation stays in the application or eino-ext.

Tests

go test ./adk/middlewares/memory/ covers required-store validation, once-per-run injection, namespace-scoped writes via WritePolicy, and no-op when WritePolicy declines.

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[ADK] Add pluggable memory middleware based on Retriever/Indexer/Embedding

1 participant