AS AgentScopeAPI 手册 / API Reference

TaskReminderMiddleware

public class TaskReminderMiddleware implements MiddlewareBase
源码Source io/agentscope/core/middleware/TaskReminderMiddleware.java:54–128

任务 Reminder 中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.core.middleware 包,实现 MiddlewareBase。核心成员包括 onSystemPrompt、onReasoning。

Keeps the agent's todo list in front of the model so long-running tasks don't drift.

Two hooks:

  • #onSystemPrompt appends a one-time, static explanation of how to use the todo_write tool (grounding).

  • #onReasoning appends a fresh <system-reminder> rendering the current AgentState.tasksContext before every reasoning step, so the model always sees the latest state regardless of how many tool calls happened since.

The reminder is appended transiently to the reasoning input only; it is never written into AgentState.context, so it is never persisted, compacted, or recalled. It is additionally tagged with Msg#METADATA_SYNTHETIC so any consumer that does observe it can skip it.

Unlike opencode (which leaves the latest list in the most recent tool output), agentscope re-injects the list every turn: after conversation compaction the tool output may be gone, but tasksContext survives, so this middleware guarantees the list is always visible.

方法摘要Method Summary

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

方法详情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/core/middleware/TaskReminderMiddleware.java:67–71

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/middleware/TaskReminderMiddleware.java:73–100

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