Skip to content

Function: plan()

@providerprotocol/agents


@providerprotocol/agents / execution / plan

plan(options): ExecutionStrategy

Defined in: src/execution/plan.ts:102

Creates a plan-then-execute strategy for agent execution.

The plan strategy implements a two-phase approach:

  1. Planning Phase: LLM generates a structured plan with steps and dependencies
  2. Execution Phase: Execute each plan step in topological order respecting dependencies

If a step fails and allowReplan is true, the strategy can generate a new plan to recover from the failure (replanning is not yet fully implemented).

This strategy is ideal for complex multi-step tasks where the execution order matters and steps may have dependencies on each other.

PlanOptions = {}

Configuration options for the plan strategy

ExecutionStrategy

An ExecutionStrategy instance implementing the plan-then-execute pattern

import { createAgent, plan } from '@providerprotocol/agents';
// Basic plan-based agent
const agent = createAgent({
llm: myLLM,
tools: [readFileTool, writeFileTool, searchTool],
strategy: plan(),
});
// With step limit and replanning
const robustAgent = createAgent({
llm: myLLM,
tools: [apiTool, dbTool],
strategy: plan({
maxPlanSteps: 10,
allowReplan: true,
}),
});
// Execute a complex task
const result = await agent.generate(
'Read config.json, update the version, and write it back'
);
console.log(result.state.plan); // Shows executed plan steps
  • loop for simpler tool-loop execution
  • react for reasoning-enhanced execution