AS AgentScopeAPI 手册 / API Reference

PlanModeMiddleware

public class PlanModeMiddleware implements HarnessRuntimeMiddleware
源码Source io/agentscope/harness/agent/middleware/PlanModeMiddleware.java:58–243

计划模式中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.harness.agent.middleware 包,实现 HarnessRuntimeMiddleware。核心成员包括 onSystemPrompt、onActing、PlanModeMiddleware。

Enforces plan mode: while AgentState.planModeContext.planActive is true, mutating tool calls are denied so the agent can only read / investigate and draft a plan.

Enforcement is deterministic and happens in #onActing: each tool call is allowed iff it is read-only or one of the plan-control tools (plan_enter / plan_write / plan_exit / todo_write); everything else gets a synthetic DENIED tool result (written to context and streamed as events) without being executed. This intentionally does not reuse PermissionMode.EXPLORE: that mode is snapshotted immutably by the PermissionEngine at construction and cannot be toggled at runtime, whereas plan mode must switch dynamically.

#onSystemPrompt injects a plan-mode banner so the model knows it is in the read-only design phase.

构造器摘要Constructor Summary

构造器Constructor说明Description
public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver)
初始化 `PlanModeMiddleware` 实例。
Creates a new instance.
public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver, Set<String> additionalAllowed)
初始化 `PlanModeMiddleware` 实例。
Creates a new instance.

方法摘要Method Summary

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

构造器详情Constructor Detail

PlanModeMiddleware

public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver)

初始化 PlanModeMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerPlanModeManager管理器(类型 `PlanModeManager`)。shared plan-mode state/file coordinator
readOnlyResolverPredicate<String>读取 Only 解析器(类型 `Predicate`)。resolves whether a tool (by name) is read-only; used to decide which calls are permitted while plan mode is active
源码Source io/agentscope/harness/agent/middleware/PlanModeMiddleware.java:120–122

PlanModeMiddleware

public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver, Set<String> additionalAllowed)

初始化 PlanModeMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerPlanModeManager管理器(类型 `PlanModeManager`)。shared plan-mode state/file coordinator
readOnlyResolverPredicate<String>读取 Only 解析器(类型 `Predicate`)。resolves whether a tool (by name) is read-only; used to decide which calls are permitted while plan mode is active
additionalAllowedSet<String>additional 已允许(类型 `Set`)。extra tool names that are permitted while plan mode is active even when not read-only (opt-in escape hatch — e.g. `execute` for shell-based investigation). The model is instructed via the plan banner to use them read-only only.
源码Source io/agentscope/harness/agent/middleware/PlanModeMiddleware.java:132–142

方法详情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/agent/middleware/PlanModeMiddleware.java:144–166

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/PlanModeMiddleware.java:168–233

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