tests — planner

Module: tests-planner Cohesion: 0.80 Members: 0

tests — planner

This documentation covers the planner module, specifically focusing on the core components responsible for managing task dependencies and delegating tasks to appropriate subagents. These components are central to how the agent breaks down a high-level goal into actionable steps and orchestrates their execution.

The tests in tests/planner/delegation-engine.test.ts and tests/planner/task-graph.test.ts validate the functionality of the DelegationEngine and TaskGraph classes, respectively, which reside in src/agent/planner/.

Module Overview

The planner module provides the foundational structures and logic for an autonomous agent to:

  1. Represent a plan as a directed acyclic graph (DAG) of tasks with dependencies.
  2. Orchestrate task execution in the correct order, handling parallel execution where possible.
  3. Delegate tasks to specialized subagents based on their description or explicit instructions.
  4. Manage task execution robustness through retries and shared context.

These capabilities enable the agent to tackle complex problems by breaking them down into smaller, manageable units and leveraging specialized tools or sub-agents for specific types of work.

Core Components

TaskGraph

The TaskGraph class (src/agent/planner/task-graph.js) is responsible for managing a collection of PlannedTask objects, their dependencies, and their execution status. It ensures tasks are processed in a valid order and provides mechanisms for tracking progress and handling failures.

Key Concepts

Functionality

The TaskGraph provides methods for:

Example Task Graph

A simple task graph with dependencies:

graph TD
    t1[Task 1] --> t2[Task 2]
    t1 --> t3[Task 3]
    t2 --> t4[Task 4]
    t3 --> t4

In this graph:

DelegationEngine

The DelegationEngine class (src/agent/planner/delegation-engine.js) is responsible for deciding which specialized subagent should handle a given PlannedTask and for managing the robust execution of these tasks, including retries and shared context.

Key Concepts

Functionality

The DelegationEngine provides methods for:

  1. Explicit delegateTo: If task.delegateTo is specified, that subagent is chosen.
  2. Custom Mappings: User-defined mappings (added via addMapping) can override or extend the default heuristics.
  3. Keyword Heuristics: The task's description is analyzed for keywords (e.g., "debug" -> debugger, "review" -> code-reviewer).
  4. Default: If no other match is found, the task defaults to the main agent.

Integration and Usage

The TaskGraph and DelegationEngine are designed to work in conjunction within the agent's planning and execution loop:

  1. An initial plan (a list of PlannedTask objects) is fed into a TaskGraph.
  2. The agent repeatedly queries the TaskGraph for getReady() tasks.
  3. For each ready task, the DelegationEngine is used to matchSubagent() and then executeWithRetry() the task. The executor function passed to executeWithRetry would typically involve invoking the identified subagent with the task details.
  4. Based on the TaskResult from executeWithRetry, the TaskGraph is updated using markComplete() or markFailed().
  5. This loop continues until all tasks are either complete, failed, or skipped.

This modular design allows for flexible planning, robust execution, and the integration of diverse specialized subagents.

Contributing to the Module

When contributing to the planner module: