Class ToolResultEvictionMiddleware

java.lang.Object
io.agentscope.harness.agent.middleware.ToolResultEvictionMiddleware
All Implemented Interfaces:
io.agentscope.core.middleware.MiddlewareBase, HarnessRuntimeMiddleware

public class ToolResultEvictionMiddleware extends Object implements 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:

  1. Writes the full result to {evictionPath}/{agentName}/{sanitized-toolCallId}-{contentHash} in the filesystem.
  2. Compacts AgentState.contextMutable() first, so legacy pre-reasoning hooks cannot hide an original result from persistence cleanup.
  3. Rebuilds the current ReasoningInput, preserving hook deletions and rewrites while replacing results that remain visible to the immediate model call.
  4. 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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.agentscope.core.middleware.MiddlewareBase

    onActing, onAgent, onModelCall, onSystemPrompt, order
  • Constructor Details

  • 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:
      onReasoning in interface io.agentscope.core.middleware.MiddlewareBase