MessageQueueMiddleware
public class MessageQueueMiddleware implements MiddlewareBase
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
SqliteBaseStorenamespace["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_IDstaticfinal | 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
当前会话线程标识字段。声明为 public static final ThreadLocal CURRENT_THREAD_ID。
Thread-local carrying the current thread ID for the in-flight agent run.
io/agentscope/harness/coding/middleware/MessageQueueMiddleware.java:58构造器详情Constructor Detail
MessageQueueMiddleware
public MessageQueueMiddleware(BaseStore store)
初始化 MessageQueueMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
store | BaseStore | 存储实例(类型 `BaseStore`)。The store. |
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
currentPrompt | String | 当前提示词(类型 `String`)。The current prompt. |
Mono<String>io/agentscope/harness/coding/middleware/MessageQueueMiddleware.java:66–82