AS AgentScopeAPI 手册 / API Reference

AsyncToolMiddleware

public class AsyncToolMiddleware implements HarnessRuntimeMiddleware
源码Source io/agentscope/harness/agent/middleware/AsyncToolMiddleware.java:65–295

异步工具中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.harness.agent.middleware 包,实现 HarnessRuntimeMiddleware。核心成员包括 onActing、AsyncToolMiddleware。

Middleware that offloads long-running tool calls to background execution.

When the acting phase exceeds the configured timeout:

  • The underlying tool execution continues in the background (never cancelled)

  • A placeholder ToolResultBlock is written to agent context so the LLM can continue reasoning

  • When the background execution completes, the real result is pushed to the session's inbox as a HintBlock and a wakeup is enqueued

The InboxMiddleware drains the inbox on the next reasoning step, making the real result available to the LLM.

构造器摘要Constructor Summary

构造器Constructor说明Description
public AsyncToolMiddleware(MessageBus messageBus, Duration offloadTimeout)
初始化 `AsyncToolMiddleware` 实例。
Creates a new instance.
public AsyncToolMiddleware(MessageBus messageBus, Duration offloadTimeout, AsyncToolRegistry asyncToolRegistry)
初始化 `AsyncToolMiddleware` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public Flux<AgentEvent> onActing(Agent agent, RuntimeContext ctx, ActingInput input, Function<ActingInput, Flux<AgentEvent>> next)
处理执行事件。
Performs the on acting operation.

构造器详情Constructor Detail

AsyncToolMiddleware

public AsyncToolMiddleware(MessageBus messageBus, Duration offloadTimeout)

初始化 AsyncToolMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
messageBusMessageBus消息总线(类型 `MessageBus`)。The message bus.
offloadTimeoutDuration卸载超时(类型 `Duration`)。The offload timeout.
源码Source io/agentscope/harness/agent/middleware/AsyncToolMiddleware.java:81–83

AsyncToolMiddleware

public AsyncToolMiddleware(MessageBus messageBus, Duration offloadTimeout, AsyncToolRegistry asyncToolRegistry)

初始化 AsyncToolMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
messageBusMessageBus消息总线(类型 `MessageBus`)。The message bus.
offloadTimeoutDuration卸载超时(类型 `Duration`)。The offload timeout.
asyncToolRegistryAsyncToolRegistry异步工具注册表(类型 `AsyncToolRegistry`)。The async tool registry.
源码Source io/agentscope/harness/agent/middleware/AsyncToolMiddleware.java:85–90

方法详情Method Detail

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/harness/agent/middleware/AsyncToolMiddleware.java:92–180

继承成员Inherited Members

基于官方固定版本源码静态生成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.