Skip to main content

Interface: IPlanningEngine

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:393

Interface for the AgentOS Planning Engine.

The Planning Engine provides sophisticated cognitive capabilities for autonomous agents, including:

  • Goal Decomposition: Break complex goals into manageable subtasks
  • Plan Generation: Create multi-step execution plans with ReAct pattern
  • Self-Correction: Refine plans based on execution feedback
  • Autonomous Loops: Pursue goals with minimal human intervention

Example

// Generate and execute a plan
const engine = new PlanningEngine(llmProvider);
const plan = await engine.generatePlan('Build a REST API', {
strategy: 'plan_and_execute',
maxSteps: 20,
});

for (const step of plan.steps) {
const result = await engine.executeStep(step);
if (!result.success) {
const refined = await engine.refinePlan(plan, {
planId: plan.planId,
stepId: step.stepId,
feedbackType: 'step_failed',
details: result.error!,
severity: 'error',
});
}
}

Methods

decomposeTask()

decomposeTask(task, depth?): Promise<TaskDecomposition>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:428

Decomposes a complex task into simpler subtasks.

Parameters

task

string

The task description to decompose

depth?

number

Maximum decomposition depth (default: 3)

Returns

Promise<TaskDecomposition>

Task decomposition result


executeStep()

executeStep(step, context?): Promise<PlanStepResult>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:472

Executes a single plan step.

Parameters

step

PlanStep

Step to execute

context?

StepExecutionContext

Execution context including previous results

Returns

Promise<PlanStepResult>

Step execution result


generatePlan()

generatePlan(goal, context?, options?): Promise<ExecutionPlan>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:415

Generates a multi-step execution plan from a high-level goal.

Parameters

goal

string

The high-level goal to achieve

context?

PlanningContext

Additional context for planning

options?

PlanningOptions

Planning configuration options

Returns

Promise<ExecutionPlan>

Generated execution plan

Example

const plan = await engine.generatePlan(
'Analyze customer feedback and generate a report',
{ domainContext: 'E-commerce platform' },
{ strategy: 'react', maxSteps: 15 }
);

getExecutionState()

getExecutionState(planId): ExecutionState | null

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:515

Gets the current execution state for a plan.

Parameters

planId

string

Plan identifier

Returns

ExecutionState | null

Current execution state or null if not found


refinePlan()

refinePlan(plan, feedback): Promise<ExecutionPlan>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:450

Refines an existing plan based on execution feedback. Uses self-reflection to identify issues and generate corrections.

Parameters

plan

ExecutionPlan

Original plan to refine

feedback

ExecutionFeedback

Feedback from execution

Returns

Promise<ExecutionPlan>

Refined execution plan


reflect()

reflect(plan, executionState): Promise<ReflectionResult>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:459

Performs self-reflection on plan execution state.

Parameters

plan

ExecutionPlan

Current plan

executionState

ExecutionState

Current execution state

Returns

Promise<ReflectionResult>

Reflection insights and suggested adjustments


restoreCheckpoint()

restoreCheckpoint(checkpointId): Promise<{ plan: ExecutionPlan; state: ExecutionState; }>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:507

Restores execution state from a checkpoint.

Parameters

checkpointId

string

Checkpoint to restore

Returns

Promise<{ plan: ExecutionPlan; state: ExecutionState; }>

Restored execution state


runAutonomousLoop()

runAutonomousLoop(goal, options?): AsyncGenerator<LoopProgress, ExecutionSummary, undefined>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:483

Runs an autonomous goal pursuit loop. Yields progress updates and handles self-correction automatically.

Parameters

goal

string

Goal to pursue

options?

AutonomousLoopOptions

Loop configuration

Returns

AsyncGenerator<LoopProgress, ExecutionSummary, undefined>

Final execution summary

Yields

Progress updates including current step and observations


saveCheckpoint()

saveCheckpoint(plan, state): Promise<string>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:499

Saves current execution state for checkpointing/rollback.

Parameters

plan

ExecutionPlan

Plan being executed

state

ExecutionState

Current execution state

Returns

Promise<string>

Checkpoint identifier


validatePlan()

validatePlan(plan): Promise<PlanValidationResult>

Defined in: packages/agentos/src/core/planning/IPlanningEngine.ts:436

Validates a plan for feasibility and completeness.

Parameters

plan

ExecutionPlan

Plan to validate

Returns

Promise<PlanValidationResult>

Validation result with any issues found