Class PlanModeMiddleware

java.lang.Object
io.agentscope.harness.agent.middleware.PlanModeMiddleware
All Implemented Interfaces:
io.agentscope.core.middleware.MiddlewareBase, HarnessRuntimeMiddleware

public class PlanModeMiddleware extends Object implements HarnessRuntimeMiddleware
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(io.agentscope.core.agent.Agent, io.agentscope.core.agent.RuntimeContext, io.agentscope.core.middleware.ActingInput, java.util.function.Function<io.agentscope.core.middleware.ActingInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>>): 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(io.agentscope.core.agent.Agent, io.agentscope.core.agent.RuntimeContext, java.lang.String) injects a plan-mode banner so the model knows it is in the read-only design phase.

  • Constructor Details

    • PlanModeMiddleware

      public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver)
      Parameters:
      manager - shared plan-mode state/file coordinator
      readOnlyResolver - resolves whether a tool (by name) is read-only; used to decide which calls are permitted while plan mode is active
    • PlanModeMiddleware

      public PlanModeMiddleware(PlanModeManager manager, Predicate<String> readOnlyResolver, Set<String> additionalAllowed)
      Parameters:
      manager - shared plan-mode state/file coordinator
      readOnlyResolver - resolves whether a tool (by name) is read-only; used to decide which calls are permitted while plan mode is active
      additionalAllowed - 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.
  • Method Details

    • onSystemPrompt

      public reactor.core.publisher.Mono<String> onSystemPrompt(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, String currentPrompt)
      Specified by:
      onSystemPrompt in interface io.agentscope.core.middleware.MiddlewareBase
    • onActing

      public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> onActing(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.ActingInput input, Function<io.agentscope.core.middleware.ActingInput,reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next)
      Specified by:
      onActing in interface io.agentscope.core.middleware.MiddlewareBase