AS AgentScopeAPI 手册 / API Reference

ToolResultEvictionMiddleware

public class ToolResultEvictionMiddleware implements HarnessRuntimeMiddleware
源码Source io/agentscope/harness/agent/middleware/ToolResultEvictionMiddleware.java:65–312

工具结果淘汰中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.harness.agent.middleware 包,实现 HarnessRuntimeMiddleware。核心成员包括 onReasoning、ToolResultEvictionMiddleware。

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

构造器Constructor说明Description
public ToolResultEvictionMiddleware(AbstractFilesystem filesystem, ToolResultEvictionConfig config)
初始化 `ToolResultEvictionMiddleware` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)
处理推理事件。
Performs the on reasoning operation.

构造器详情Constructor Detail

ToolResultEvictionMiddleware

public ToolResultEvictionMiddleware(AbstractFilesystem filesystem, ToolResultEvictionConfig config)

初始化 ToolResultEvictionMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
filesystemAbstractFilesystem文件系统(类型 `AbstractFilesystem`)。The filesystem.
configToolResultEvictionConfig配置对象(类型 `ToolResultEvictionConfig`)。The config.
源码Source io/agentscope/harness/agent/middleware/ToolResultEvictionMiddleware.java:73–77

方法详情Method Detail

onReasoning

public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)

处理推理事件。

Performs the on reasoning operation.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
inputReasoningInput输入消息(类型 `ReasoningInput`)。The input.
nextFunction<ReasoningInput, Flux<AgentEvent>>下一个(类型 `Function >`)。The next.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/middleware/ToolResultEvictionMiddleware.java:79–111

继承成员Inherited Members

继承自Methods inherited from MiddlewareBase
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.