ToolResultEvictionMiddleware
public class ToolResultEvictionMiddleware implements HarnessRuntimeMiddleware
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
构造器详情Constructor Detail
ToolResultEvictionMiddleware
public ToolResultEvictionMiddleware(AbstractFilesystem filesystem, ToolResultEvictionConfig config)
初始化 ToolResultEvictionMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filesystem | AbstractFilesystem | 文件系统(类型 `AbstractFilesystem`)。The filesystem. |
config | ToolResultEvictionConfig | 配置对象(类型 `ToolResultEvictionConfig`)。The config. |
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
input | ReasoningInput | 输入消息(类型 `ReasoningInput`)。The input. |
next | Function<ReasoningInput, Flux<AgentEvent>> | 下一个(类型 `Function >`)。The next. |
Flux<AgentEvent>io/agentscope/harness/agent/middleware/ToolResultEvictionMiddleware.java:79–111