类 PendingToolRecoveryHook

java.lang.Object
io.agentscope.core.hook.PendingToolRecoveryHook
所有已实现的接口:
Hook

public class PendingToolRecoveryHook extends Object implements Hook
Hook that automatically recovers from orphaned pending tool calls by generating error ToolResultBlocks before the agent processes new input.

When tool execution fails, times out, or is interrupted, tool call states may remain in memory without corresponding results. This hook detects such orphaned pending tool calls at PreCallEvent time and patches them with synthetic error results, allowing the agent to continue processing instead of crashing with IllegalStateException.

This hook is registered by default in ReActAgent.Builder. Users can disable it via ReActAgent.Builder.enablePendingToolRecovery(boolean) if they prefer to handle pending tool calls manually (e.g., through HITL mechanisms).

Behavior:

  • Only activates when the agent is a ReActAgent
  • Only patches when pending tool calls exist AND user input does not contain ToolResultBlocks (i.e., user is not providing results themselves)
  • Generated error results are added to memory as TOOL-role messages
另请参阅:
  • 构造器详细资料

    • PendingToolRecoveryHook

      public PendingToolRecoveryHook()
  • 方法详细资料

    • onEvent

      public <T extends HookEvent> reactor.core.publisher.Mono<T> onEvent(T event)
      从接口复制的说明: Hook
      Handle a hook event.

      This method is called for all agent execution events. Use pattern matching to handle specific event types.

      Modifiable Events: For events with setters, you can modify the context and the changes will affect agent execution:

      Notification Events: Events without setters are read-only:

      指定者:
      onEvent 在接口中 Hook
      类型参数:
      T - The concrete event type
      参数:
      event - The hook event
      返回:
      Mono containing the potentially modified event
    • priority

      public int priority()
      从接口复制的说明: Hook
      The priority of this hook (lower value = higher priority).

      Hooks are executed in ascending priority order. Hooks with the same priority execute in their registration order.

      Common Priority Ranges:

      • 0-50: Critical system hooks (auth, security)
      • 51-100: High priority hooks (validation, preprocessing)
      • 101-500: Normal priority hooks (business logic)
      • 501-1000: Low priority hooks (logging, metrics)
      指定者:
      priority 在接口中 Hook
      返回:
      The priority value (default: 100)