AS AgentScopeAPI 手册 / API Reference

GracefulShutdownMiddleware

public final class GracefulShutdownMiddleware implements MiddlewareBase
源码Source io/agentscope/core/shutdown/GracefulShutdownMiddleware.java:53–96

Graceful Shutdown 中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.core.shutdown 包,实现 MiddlewareBase。核心成员包括 onReasoning、onActing、GracefulShutdownMiddleware。

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 io.agentscope.core.agent.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).

构造器摘要Constructor Summary

构造器Constructor说明Description
public GracefulShutdownMiddleware(GracefulShutdownManager manager)
初始化 `GracefulShutdownMiddleware` 实例。
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.
public Flux<AgentEvent> onActing(Agent agent, RuntimeContext ctx, ActingInput input, Function<ActingInput, Flux<AgentEvent>> next)
处理执行事件。
Performs the on acting operation.

构造器详情Constructor Detail

GracefulShutdownMiddleware

public GracefulShutdownMiddleware(GracefulShutdownManager manager)

初始化 GracefulShutdownMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerGracefulShutdownManager管理器(类型 `GracefulShutdownManager`)。The manager.
源码Source io/agentscope/core/shutdown/GracefulShutdownMiddleware.java:59–61

方法详情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/core/shutdown/GracefulShutdownMiddleware.java:63–76

onActing

public Flux<AgentEvent> onActing(Agent agent, RuntimeContext ctx, ActingInput input, Function<ActingInput, Flux<AgentEvent>> next)

处理执行事件。

Performs the on acting operation.

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

继承成员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.