PlanModeMiddleware
public class PlanModeMiddleware implements HarnessRuntimeMiddleware
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
方法摘要Method Summary
构造器详情Constructor Detail
PlanModeMiddleware
public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver)
初始化 PlanModeMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
manager | PlanModeManager | 管理器(类型 `PlanModeManager`)。shared plan-mode state/file coordinator |
readOnlyResolver | Predicate<String> | 读取 Only 解析器(类型 `Predicate`)。resolves whether a tool (by name) is read-only; used to decide which calls are permitted while plan mode is active |
io/agentscope/harness/agent/middleware/PlanModeMiddleware.java:120–122PlanModeMiddleware
public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver, Set<String> additionalAllowed)
初始化 PlanModeMiddleware 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
manager | PlanModeManager | 管理器(类型 `PlanModeManager`)。shared plan-mode state/file coordinator |
readOnlyResolver | Predicate<String> | 读取 Only 解析器(类型 `Predicate`)。resolves whether a tool (by name) is read-only; used to decide which calls are permitted while plan mode is active |
additionalAllowed | Set<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. |
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
currentPrompt | String | 当前提示词(类型 `String`)。The current prompt. |
Mono<String>io/agentscope/harness/agent/middleware/PlanModeMiddleware.java:144–166onActing
public Flux<AgentEvent> onActing(Agent agent, RuntimeContext ctx, ActingInput input, Function<ActingInput, Flux<AgentEvent>> next)
处理执行事件。
Performs the on acting operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
input | ActingInput | 输入消息(类型 `ActingInput`)。The input. |
next | Function<ActingInput, Flux<AgentEvent>> | 下一个(类型 `Function >`)。The next. |
Flux<AgentEvent>io/agentscope/harness/agent/middleware/PlanModeMiddleware.java:168–233