类 GracefulShutdownMiddleware

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

public final class GracefulShutdownMiddleware extends Object implements MiddlewareBase
System middleware that integrates graceful shutdown into the agent lifecycle.

Per-call request registration and unregistration are handled by AgentBase.call(): each call registers a distinct requestId (carried on the Reactor Context under AgentBase.SHUTDOWN_REQUEST_ID_KEY) and unregisters it via doFinally, guaranteeing that every registered request is always unregistered regardless of success, error, or cancel — and that concurrent calls on one agent instance are tracked independently.

This middleware is responsible for:

  • onAgent — deduplicate input if resuming from a shutdown-interrupted session
  • onReasoning (doOnComplete) — checkpoint after reasoning
  • onActing (doOnComplete) — checkpoint after acting

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), so reasoning/acting 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).

  • 构造器详细资料

  • 方法详细资料

    • onReasoning

      public reactor.core.publisher.Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput,reactor.core.publisher.Flux<AgentEvent>> next)
      从接口复制的说明: MiddlewareBase
      Intercept the reasoning phase (LLM call + streaming output parsing).
      指定者:
      onReasoning 在接口中 MiddlewareBase
      参数:
      agent - the agent instance
      ctx - per-call runtime context (session, user, attributes)
      input - reasoning input (messages, tools, options)
      next - calls the next middleware or the core reasoning logic
      返回:
      event stream from reasoning
    • onActing

      public reactor.core.publisher.Flux<AgentEvent> onActing(Agent agent, RuntimeContext ctx, ActingInput input, Function<ActingInput,reactor.core.publisher.Flux<AgentEvent>> next)
      从接口复制的说明: MiddlewareBase
      Intercept the tool-call execution phase.
      指定者:
      onActing 在接口中 MiddlewareBase
      参数:
      agent - the agent instance
      ctx - per-call runtime context (session, user, attributes)
      input - acting input (the tool calls)
      next - calls the next middleware or the core acting logic
      返回:
      event stream from acting