Class MemoryFlushMiddleware
- All Implemented Interfaces:
io.agentscope.core.middleware.MiddlewareBase,HarnessRuntimeMiddleware
Runs in onAgent(io.agentscope.core.agent.Agent, io.agentscope.core.agent.RuntimeContext, io.agentscope.core.middleware.AgentInput, java.util.function.Function<io.agentscope.core.middleware.AgentInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>>)'s doOnComplete so long-term memories are extracted and
persisted after every call, even when conversation compaction was not triggered during that
call. The flush is fire-and-forget: the agent stream completes immediately while the
extraction runs on a background scheduler. When CompactionMiddleware is active, it
handles flush/offload for the messages it summarizes; this middleware covers the remaining
tail of messages that were kept verbatim.
Flush is gated by a MemoryConfig.FlushTrigger:
MemoryConfig.FlushMode.ALWAYS(default) — flush after every call.MemoryConfig.FlushMode.NEVER— never flush via this middleware. The CompactionMiddleware and overflow-recovery paths still run their own flush when they fire.MemoryConfig.FlushMode.THROTTLED— flush at most once perMemoryConfig.FlushTrigger.minGap().
Session transcript append is not handled here — see TranscriptMiddleware,
which runs independently of memory flush so history stays complete even when flush is
disabled.
Concurrent flushes for the same isolation key are serialised: at most one flush runs per key at a time, and pending flushes of the same conversation coalesce into a single queued task, because a queued task reads the conversation state only when it executes and the newest task therefore subsumes the ones it replaces. Flushes of distinct conversations under the same key are queued separately.
The class is thread-safe: instances hold only configuration, and the per-key queues live in a static map and are synchronised internally.
The throttle window is tracked per isolation key, which matches the memory data isolation in use:
IsolationScope.USER(default) — one window peruserId.IsolationScope.SESSION— one window persessionId.IsolationScope.AGENT/IsolationScope.GLOBAL— one shared window for the whole agent instance (prevents concurrent flush races on shared memory files).
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model) MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String flushPrompt, MemoryConfig.FlushTrigger flushTrigger) MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String flushPrompt, MemoryConfig.FlushTrigger flushTrigger, IsolationScope isolationScope) MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String flushPrompt, MemoryConfig.FlushTrigger flushTrigger, IsolationScope isolationScope, PeriodicGate periodicGate) -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>onAgent(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.AgentInput input, Function<io.agentscope.core.middleware.AgentInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.core.middleware.MiddlewareBase
onActing, onModelCall, onReasoning, onSystemPrompt, order
-
Constructor Details
-
MemoryFlushMiddleware
public MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model) -
MemoryFlushMiddleware
public MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String flushPrompt, MemoryConfig.FlushTrigger flushTrigger) -
MemoryFlushMiddleware
public MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String flushPrompt, MemoryConfig.FlushTrigger flushTrigger, IsolationScope isolationScope) -
MemoryFlushMiddleware
public MemoryFlushMiddleware(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String flushPrompt, MemoryConfig.FlushTrigger flushTrigger, IsolationScope isolationScope, PeriodicGate periodicGate)
-
-
Method Details
-
onAgent
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> onAgent(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.AgentInput input, Function<io.agentscope.core.middleware.AgentInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next) - Specified by:
onAgentin interfaceio.agentscope.core.middleware.MiddlewareBase
-