类 GracefulShutdownHook

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

public final class GracefulShutdownHook extends Object implements Hook
System hook that integrates graceful shutdown into the agent lifecycle.

Request registration and unregistration are handled by AgentBase.call() via Mono.using (setup registers, cleanup unregisters), guaranteeing that every registered request is always unregistered regardless of success, error, or cancel.

This hook is responsible for:

  • PreCallEvent — deduplicate input if resuming from a shutdown-interrupted session

Shutdown checkpoints — when the system is in SHUTTING_DOWN state, the agent is interrupted at these safe points (after the current phase has fully completed):

This means during shutdown, reasoning/acting/summary phases are allowed to complete before the interrupt is issued — output tokens are not wasted. Only when the global shutdown timeout is reached will the agent be force-interrupted mid-phase (handled by GracefulShutdownManager#enforceTimeoutAndInterrupt).

  • 构造器详细资料

  • 方法详细资料

    • 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)