AS AgentScopeAPI 手册 / API Reference

MessageQueueMiddleware

public class MessageQueueMiddleware implements MiddlewareBase
源码Source io/agentscope/harness/coding/middleware/MessageQueueMiddleware.java:50–105

消息队列中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.harness.coding.middleware 包,实现 MiddlewareBase。核心成员包括 onSystemPrompt、MessageQueueMiddleware、CURRENT_THREAD_ID。

Middleware that injects queued messages into the system prompt before each LLM reasoning step.

  • Reads the current thread ID from #CURRENT_THREAD_ID (set by the dispatcher)

  • Checks SqliteBaseStore namespace ["queue", thread_id]

  • Appends all queued messages to the system prompt via #onSystemPrompt

  • Clears the queue after injection

The caller (webhook handler / CLI dispatcher) must set #CURRENT_THREAD_ID before calling gateway.run() and remove it after:

`MessageQueueMiddleware.CURRENT_THREAD_ID.set(threadId);
try {
gateway.run(ctx, messages, address).block();
} finally {
MessageQueueMiddleware.CURRENT_THREAD_ID.remove();
}
`

字段摘要Field Summary

字段Field类型Type说明Description
CURRENT_THREAD_ID
staticfinal
ThreadLocal<String>
当前会话线程标识字段。
Thread-local carrying the current thread ID for the in-flight agent run.

构造器摘要Constructor Summary

构造器Constructor说明Description
public MessageQueueMiddleware(BaseStore store)
初始化 `MessageQueueMiddleware` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public Mono<String> onSystemPrompt(Agent agent, RuntimeContext ctx, String currentPrompt)
处理系统提示词事件。
Performs the on system prompt operation.

字段详情Field Detail

CURRENT_THREAD_ID

public static final ThreadLocal<String> CURRENT_THREAD_ID
staticfinal

当前会话线程标识字段。声明为 public static final ThreadLocal CURRENT_THREAD_ID。

Thread-local carrying the current thread ID for the in-flight agent run.

源码Source io/agentscope/harness/coding/middleware/MessageQueueMiddleware.java:58

构造器详情Constructor Detail

MessageQueueMiddleware

public MessageQueueMiddleware(BaseStore store)

初始化 MessageQueueMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
storeBaseStore存储实例(类型 `BaseStore`)。The store.
源码Source io/agentscope/harness/coding/middleware/MessageQueueMiddleware.java:62–64

方法详情Method Detail

onSystemPrompt

public Mono<String> onSystemPrompt(Agent agent, RuntimeContext ctx, String currentPrompt)

处理系统提示词事件。

Performs the on system prompt operation.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
currentPromptString当前提示词(类型 `String`)。The current prompt.
返回Returns Mono<String>
返回Mono。Returns mono.
源码Source io/agentscope/harness/coding/middleware/MessageQueueMiddleware.java:66–82

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