Class ToolResultEvictionMiddleware
java.lang.Object
io.agentscope.harness.agent.middleware.ToolResultEvictionMiddleware
- All Implemented Interfaces:
io.agentscope.core.middleware.MiddlewareBase,HarnessRuntimeMiddleware
Middleware that evicts oversized tool results to the
AbstractFilesystem before
downstream reasoning sees the bloated message list.
When the text content of a ToolResultBlock in canonical agent state or the current
reasoning view exceeds ToolResultEvictionConfig.getMaxResultChars(), this middleware:
- Writes the full result to
{evictionPath}/{agentName}/{sanitized-toolCallId}-{contentHash}in the filesystem. - Compacts
AgentState.contextMutable()first, so legacy pre-reasoning hooks cannot hide an original result from persistence cleanup. - Rebuilds the current
ReasoningInput, preserving hook deletions and rewrites while replacing results that remain visible to the immediate model call. - Marks compacted results in metadata so they are not recursively evicted on later turns.
Tools listed in ToolResultEvictionConfig.getExcludedToolNames() are never evicted
(e.g. readFile — evicting would cause re-read loops).
-
Constructor Summary
ConstructorsConstructorDescriptionToolResultEvictionMiddleware(AbstractFilesystem filesystem, ToolResultEvictionConfig config) -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>onReasoning(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.ReasoningInput input, Function<io.agentscope.core.middleware.ReasoningInput, 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, onAgent, onModelCall, onSystemPrompt, order
-
Constructor Details
-
ToolResultEvictionMiddleware
-
-
Method Details
-
onReasoning
public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> onReasoning(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.ReasoningInput input, Function<io.agentscope.core.middleware.ReasoningInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next) - Specified by:
onReasoningin interfaceio.agentscope.core.middleware.MiddlewareBase
-