planning

The agent capability to break complex goals into ordered subtasks, create execution plans, and adapt when steps fail. Enables solving multi-step problems.

Syntax

ai-agents
1. Analyze goal
2. Decompose into subtasks
3. Order by dependencies
4. Execute + monitor
5. Replan on failure

Example

ai-agents
// Plan-and-execute agent:
const planPrompt = `
Task: {task}
Available tools: {tools}

Create a step-by-step plan to complete this task.
Output as JSON: { steps: [{ action, tool, reason }] }
`;

const plan = await llm.invoke(planPrompt);
for (const step of plan.steps) {
  const result = await executeTool(step.tool, step.action);
  if (!result.success) {
    plan = await replan(task, step, result.error);
  }
}